I am trying to rebin a matrix to a larger size in matlab. In IDL you can always use rebin(matrix,dimension) to generate the new matrix. Is there any equivalent function in matlab, or do I have to manipulate the interp() function in matlab?
Thanks
It seems like imresize() does the job. It can resize a matrix to given dimension.
Related
I am trying to perform a multiple linear regression in MATLAB using the regress function, and I am using a number of different variables that involve different scales and units. I am assume the answer to this question is yes, but should I normalize each variable before running the regression? I'm not sure if MATLAB does so automatically. Thanks for the help!
Yes, you should. If you want to normalize it between 0 and 1, you could use mat2gray function (assuming "vector" as your list of variables).
norm_vect = mat2gray(vector);
This function is used to convert matrix into an image, but works well if you don't want to write yours. You also can use a simple normalization like:
for i = 1:length(vector)
norm_vect(i) = (vector(i)-min(vector))/(max(vector)-min(vector));
end
This might be simple and I apologize if it is so.
In matlab I have a double precision matrix which can theoretically have the range of +/- infinity.
I would to use the histogram function in matlab to change the values of the matrix.
For instance, if data elements fall within histogram bin 1 then I would like to assign the value of 1 to this and all of its instances.
Is there a quick and cheap way of doing this?
I have tried lookuptables etc but matlabs LUT is a pain.
Thank you for looking at my question
I think I just cracked it ...
Make a new function out of hist and after edges in the m file add this line:
[~,my_labels] = histc(y,edges,1);
and my_labels will contain your matrix with the histogram values instead of the actual values.
How to plot a 3D figure in MATLAB based on a function like f(x,y,z)=0?
And this complicated function can not be written as z = f(x,y).
f(x,y,z)=sum(a.*exp(sv(:,1)-x).^2+sv(:,2)-y).^2+sv(:,3)-z).^2)-b=0
where a is a known vector, sv is a known matrix, b is a known value. x,y,z are three variables. How to draw this surface in 3D way in matlab?
I just solve this question by this tool from the Matlab File Exchange:
Ezimplot3: implicit 3D functions plotter
your function only contains 1D vectors( I am assuming they are of equal lengths), if summed it will give you a constant; therefore, there is really nothing to plot.
I know that when I use the PDE toolbox in Matlab to solve a PDE the result is a vector, which represents the values of the function in each vertex of the mesh.
Is there a command in the PDE toolbox such that we could transform the vector solution into a piecewise linear function on the domain of definition, so that we could be able to use it like u(x,y) to find directly the approximate value in (x,y)?
I don't know about such function. But your solution is defined on a structured rectangular grid. If you simply need to interpolate data on a 2D rectangular grid, you can use interp2 for that. If your grid is made of triangles, use TriScatteredInterp. If you want to use different interpolation (e.g., FEM), you will have to implement it yourself.
How do I make a function that calculates the variance of a 2D matrix using loops i and j...where do I start?
You would not use loop variables in Matlab since this is inevitably much slower than using inbuilt (vectorized) functions.
The function var calculates the variance of a matrix column-wise. With (:) you convert a 2D matrix into a single column.
Or as Jonas pointed out, use:
var(array(:))
var1 = var(double(twoDarray(:)));
You could use reshape in order to transform image as a vector. After that, you could calculate the variance using:
v1 = var(reshape(im2(:,:),[],1));