I have a matrix X, the size of which is 100*2000 double. I want to know which kind of scaling technique is applied to matrix X in the following command, and why it does not use z-score to do scaling?

```
X = X./repmat(sqrt(sum(X.^2)),size(X,1),1);
```

I have a matrix X, the size of which is 100*2000 double. I want to know which kind of scaling technique is applied to matrix X in the following command, and why it does not use z-score to do scaling?

```
X = X./repmat(sqrt(sum(X.^2)),size(X,1),1);
```

That scaling comes from linear algebra. That's what we call normalizing by producing a unit vector. Assuming that each row is an observation and each column is a feature, what's happening here is that we are going through every observation that you collected and normalizing each feature value over all observations such that the overall length / magnitude of a particular feature for all observations is set to 1.

The bottom division takes a look at each feature and determines the norm or magnitude of the feature over all observations. Once you find these magnitudes, you then take each feature for each observation and divide by their respective magnitudes.

The reason why unit vectors are often employed is to describe a point in feature space with respect to a set of basis vectors. Normalizing by producing unit vectors gives you the smallest possible way to represent one component in feature space and so what's probably happening here is that the observations are now being transformed such that each component / feature is being represented in terms of a set of basis vectors. Each basis vector is one feature in the data.

Check out the Wikipedia article on Unit Vectors for more details: http://en.wikipedia.org/wiki/Unit_vector

Using repelem and mat2cell lens = cellfun(@numel, A); out = mat2cell(repelem(B,lens).*ones(1,sum(lens)),1,lens) Note: cellfun is looping in disguise. But, here cellfun is used to find the number of elements alone. So this could be considered almost vectorised :P repelem function is introduced in R2015a. You may not be able to run...

I assume with "2d-line" you mean a 2d-plot. This is done by the plot-function, so there is no need of surf or mesh. Sorry, when I got you wrong. The following code does what I think you asked for: % Generate some propagating wave n = 20; t = linspace(0,10,100);...

Yes by combining histc() and accumarray(): F =[1.0000 1.0000;... 2.0000 1.0000;... 3.0000 1.0000;... 3.1416 9.0000;... 4.0000 1.0000;... 5.0000 1.0000;... 6.0000 1.0000;... 6.2832 9.0000;... 7.0000 1.0000;... 8.0000 1.0000;... 9.0000 1.0000;... 9.4248 9.0000;... 10.0000 1.0000]; range=1:0.5:10; [~,bin]=histc(F(:,1),range); result= [range.' accumarray(bin,F(:,2),[])] If you run the code keep in mind that I changed the...

I would recommend a fourier regression, rather than polynomial regression, i.e. rho = a0 + a1 * cos(theta) + a2 * cos(2*theta) + a3 * cos(3*theta) + ... b1 * sin(theta) + b2 * sin(2*theta) + b3 * sin(3*theta) + ... for example, given the following points >> plot(x, y,...

This is called "skeletonization" and you can do it with the function bwmorph: bwmorph(Img, 'skel', Inf); Best...

image,matlab,image-processing,computer-vision

You can use the bitdepth parameter to set that. imwrite(img,'myimg.png','bitdepth',16) Of course, not all image formats support all bitdepths, so make sure you are choosing the the right format for your data....

Not the fastest way, but you could do it as follows: Saving the desired variables in a temporary file Loading that file to get all those variables in a struct array Converting that struct array to a cell array That is, save temp_file -regexp data\d+ %// step 1 allData =...

You can read the file using: >> open classreg.regr.modelutils.tstats This will open "tstats.m". The path of that file on your drive can be a acccessed using: >> which classreg.regr.modelutils.tstats In this folder there are all the other m-files which belong to this class....

matlab,loops,for-loop,while-loop,do-while

You could do this using conv without loops avg_2 = mean([A(1:end-1);A(2:end)]) avg_4 = conv(A,ones(1,4)/4,'valid') avg_8 = conv(A,ones(1,8)/8,'valid') Output for the sample Input: avg_2 = 0.8445 5.9715 -0.6205 -3.5505 2.5530 6.9475 10.6100 12.5635 6.4600 avg_4 = 0.1120 1.2105 0.9662 1.6985 6.5815 9.7555 8.5350 avg_8 = 3.3467 5.4830 4.7506 Finding Standard Deviation...

In increasing order of generality: If the second column is always cyclical: reshape and sum: result = sum(reshape(A(:,1), m, []), 2); If the second column consists of integers: use accumarray: result = accumarray(A(:,2), A(:,1)); In the most general case, you need unique before accumarray: [~, ~, u] = unique(A(:,2)); result...

The following code implements only a part of what I can see in the description. It generates the noise processes and does what is described in the first part. The autocorrelation is not calculated with the filter coefficients but with the actual signal. % generate noise process y y =...

You need to add "noise" to the radius of the circle, roughly around r=1: th = linspace( 0, 2*pi, N ); %// N samples noise = rand( 1, N ) * .1; %// random noise in range [0..0.1] r = 1+noise; %// add noise to r=1 figure; plot( r.*cos(th), r.*sin(th)...

image,matlab,image-processing,image-segmentation

If you simply want to ignore the columns/rows that lie outside full sub-blocks, you just subtract the width/height of the sub-block from the corresponding loop ranges: overlap = 4 blockWidth = 8; blockHeight = 8; count = 1; for i = 1:overlap:size(img,1) - blockHeight + 1 for j = 1:overlap:size(img,2)...

This is quite simple; just feed into subplot the locations as a vector. For instance, x = -2*pi:0.01:2*pi; subplot(2,2,[1,3]) plot(x,sin(x)) subplot(2,2,2) plot(x,cos(x)) subplot(2,2,4) plot(x,x.^2) gives: ...

Using IRanges, you should use findOverlaps or mergeByOverlaps instead of countOverlaps. It, by default, doesn't return no matches though. I'll leave that to you. Instead, will show an alternate method using foverlaps() from data.table package: require(data.table) subject <- data.table(interval = paste("int", 1:4, sep=""), start = c(2,10,12,25), end = c(7,14,18,28)) query...

r,excel,statistics,dataset,google-adwords

Try library(data.table) setDT(df1)[, list(Clicked=rep(c(1,0), c(Clicks, Impressions-Clicks)), Converted=rep(c(1,0), c(Conversions, Impressions-Conversions))) , Keyword] # Keyword Clicked Converted # 1: SampleName 1 1 # 2: SampleName 1 1 # 3: SampleName 1 0 # 4: SampleName 1 0 # 5: SampleName 1 0 # 6: SampleName 0 0 # 7: SampleName 0 0...

Morphological operations are suitable but i would suggest line structuring element as your arrangement is horizontal and you do not want overlaps between lines: clear clc close all BW = im2bw(imread('Silhouette.png')); BW = imclearborder(BW); se = strel('line',10,0); dilateddBW = imdilate(BW,se); img= imerode(BW,se); figure; imshow(img) ...

You might have a loop going through the "b"cellarray containing the "filenames" and: 1)get the filename by converting the content of the i-th to a string by using "char" function 2)call "save" specifying the filename (see previous point) and the list of scalar you want to save in it (in...

As suggested in the comments, the error is because x is of dimension 3x2 and theta of dimension 1x2, so you can't do X*theta. I suspect you want: theta = [0;1]; % note the ; instead of , % theta is now of dimension 2x1 % X*theta is now a...

Generally this is done (if the eq is in the format you have) with an Ax=b system. Let me show you how to do it with a simple example of 2 eq with 2 unknowns. 3*l1-4*l2=3 5*l1 -3*l2=-4 You can build the system as: x (unknowns) will be a unknowns...

The "weird behavior and lag" you see is almost always a result of callbacks interrupting each other's execution, and repeated unnecessary executions of the same callbacks piling up. To avoid this, you can typically set the Interruptible property of the control/component to 'off' instead of the default 'on', and set...

First, you have to know that fitcknn & ClassificationKNN.fit will end up with the same result. The difference is that fitcknn is a more recent version, so it allows more options. As an example, if you use load fisheriris; X = meas; Y = species; Then this code will work...

http://www.mathworks.com/help/matlab/matlab_prog/continue-long-statements-on-multiple-lines.html Continue Long Statements on Multiple Lines This example shows how to continue a statement to the next line using ellipsis (...). s = 1 - 1/2 + 1/3 - 1/4 + 1/5 ... - 1/6 + 1/7 - 1/8 + 1/9; ...

You don't need to use a loop, use intersect instead. [~,ic,ip] = intersect(c(:, 1:3),p(:, 1:3),'rows'); m = [c(ic, :), p(ip,end)]; Edit: If you want to include NaNs where they don't intersect like the above poster. function m = merge(c, p, nc, np) %check for input arg errors if nargin ==...

Rewrite the quantity to minimise as ||Xa - b||^2 = (definition of the Frobenius norm) Tr{(Xa - b) (Xa - b)'} = (expand matrix-product expression) Tr{Xaa'X' - ba'X' - Xab' + bb'} = (linearity of the trace operator) Tr{Xaa'X'} - Tr{ba'X'} - Tr{Xab'} + Tr{bb'} = (trace of transpose of...

The strings defined in the legend command are assigned in order of the plots being generated. This means that your first string 'signal1' is assigned to the plot for signal1 and the second string 'signal2' is assigned to the vertical line. You have two possibilities to fix this problem. Execute...

Java components that are generated from MATLAB code using deploytool (or using other functionality from MATLAB deployment products such as MATLAB Compiler, MATLAB Builder etc.) depend on the MATLAB Compiler Runtime (MCR). The MCR has much too large a footprint to run on an Android device, and it's really not...

You would need to change your back slashes \ to forward slashes /, otherwise some \ followed by a letter may be commands in the sprintffunction, like for example \N or \a. See sprintf documentation in the formatSpecarea for more information. original_image=imread(sprintf('D:/Academics/New folder/CUB_200_2011/images/%s', C{1}{2*(image_count)})); ...

You can change the XTickLabels property using your own format: set(gca,'XTickLabels',sprintfc('1e%i',0:numel(xt)-1)) where sprintfc is an undocumented function creating cell arrays filled with custom strings and xt is the XTick you have fetched from the current axis in order to know how many of them there are. Example with dummy data:...

I think you are missing the x limit. xlim([0 2.5*a]) ...

Use w+ or r+ when using fopen, depending on what you want to do with the file and whethe you want to create it or simply open it. From (http://www.tutorialspoint.com/c_standard_library/c_function_fopen.htm) "r" Opens a file for reading. The file must exist. "w" Creates an empty file for writing. If a file...

From the Matlab forums, the dir command output sorting is not specified, but it seems to be purely alphabetical order (with purely I mean that it does not take into account sorter filenames first). Therefore, you would have to manually sort the names. The following code is taken from this...

You need to comment those statements like this r(:,1) = a(:,1) ... % this is a constant - a(:,2); % this is a variable for more information read this ...

Unless you have some implementation bug (test your code with synthetic, well separated data), the problem might lay in the class imbalance. This can be solved by adjusting the missclassification cost (See this discussion in CV). I'd use the cost parameter of fitcsvm to increase the missclassification cost of the...

matlab,matrix,multidimensional-array,scalar

Errr, why you multiply indexes instead of values? I tried this: comDatabe(:,:,[1 2 3],:,8) = comDatabe(:,:,[1 2 3],:,8)*-1 And it worked....

Here's another indexing-based approach: n = 10; C = [A; B]; [~, ind] = sort([1:size(A,1) n*(1:size(B,1))+.5]); C = C(ind,:); ...

arrays,matlab,math,for-loop,while-loop

In the meanSum line, you should write A(k:k+2^n-1) You want to access the elements ranging from k to k+2^n-1. Therefore you have to provide the range to the selection operation. A few suggestions: Use a search engine or a knowlegde base to gather information on the error message you received....

excel,matlab,cluster-analysis,k-means,geo

I think you are looking for "path planning" rather than clustering. The traveling salesman problem comes to mind If you want to use clustering to find the individual regions you should find the coordinates for each location with respect to some global frame. One example would be using Latitude and...

The documentation: http://www.mathworks.com/help/matlab/ref/load.html, shows that you can supply a string to load by doing: load(filename) where filename is a string. In your case, you can do: load(['sourceETA/Record1/result',num2str(n),'.txt']) ...

You can extract the numerator and denominator with numden, then get their coefficiens with coeffs, normalize the polynomials, and divide again. [n,d] = numden(T); cn = coeffs(n); cd = coeffs(d); T = (n/cn(end))/(d/cd(end)); The output of latex(T) (note: no simplifyFraction now; it would undo things): Of course this isn't equal...

See docs for unique. Assuming widths and heights are column vectors, [C,ia,ic] = unique([widths, heights],'rows') In contrary, if widths and heights are row vectors, [C,ia,ic] = unique([widths; heights].','rows') ...

TL;DL: net.trainParam.max_fail = 8; I've used the example provided in the page you linked to get a working instance of nntraintool. When you open nntraintool.m you see a small piece of documentation that says (among else): % net.<a href="matlab:doc nnproperty.net_trainParam">trainParam</a>.<a href="matlab:doc nnparam.showWindow">showWindow</a> = false; This hinted that some properties are...

You should be able to use properties s = 100; d = zeros(1,100); end right? If you already have the 100 as a default for s, you should also be able to provide this as part of the default for d. I'm guessing that you're trying to avoid doing that...

inputdlg returns a cell array of strings. You can convert to double with str2double: units = str2double(inputdlg(question, title)); ...

matlab,distribution,sampling,random-sample

So, you can use this, for example: y = 0.8 + rand*0.4; this will generate random number between 0.8 and 1.2. because rand creates uniform distribution I believe that rand*0.4 creates the same ;) ...

image,matlab,image-processing,mask,boundary

It's very simple. I actually wouldn't use the code above and use the image processing toolbox instead. There's a built-in function to remove any white pixels that touch the border of the image. Use the imclearborder function. The function will return a new binary image where any pixels that were...

Use unique with the 'stable'option: str = 'FDFACCFFFBDCGGHBBCFGE'; result = unique(str, 'stable'); If you want something more manual: use bsxfun to build a logical index of the elements that haven't appeared (~any(...)) before (triu(..., 1)): result = str(~any(triu(bsxfun(@eq, str, str.'), 1))); ...

You can use calllib to call functions in shared library. This would be the newlib.h #ifdef __cplusplus extern "C"{ #endif void *init(int device); #ifdef __cplusplus } #endif and this would be the newlib.cpp file #include "newlib.h" #include "yourlib.h" A *p; extern "C" void *init(int device) { p = new A;...

My bet is that trf is a very large matrix. In these cases, the surface has so many edges (coloured black by default) that they completely clutter the image, and you don't see the surface patches One solution for that is to remove the edges: surf(trf, 'edgecolor', 'none'). Example: with...

M =[0 0 0 0 0 1 0 0 0 0 0 2 0 0 0 0 0 2 0 0 0 0 0 1 0 1 0 0 0 1 0 4 0 0 0 0 0 3 0 0 6 0 0 4 0 0 3 0 0...