I have a 2D matrix of dimensions 64 x 727. What I would like to do is separate each of the columns, creating a 3D matrix of dimensions 64 x 1 x 727.
I have looked through several similar questions on here, but my limited matlab ability is preventing me from applying previous answers to my own issue.
Many thanks,
Robbie
Try
reshape(matrix,64,1,727)
if that doesn't produce what you want explain further.
Try this:
x2d = rand(64, 727);
x3d = reshape(x2d, 64, 1, 727);
Use:
permute(matrix,[1 3 2])
switches 2nd and 3rd dimensions
Related
I need to generate some random 2D points (for example 30 points) near the y=x line, insert them in a matrix, plot it and then calculate the SVD of the matrix. But since I'm new to MATLAB I don't know how can I generate my desired matrix.
Since this looks like homework I'll just post some general ideas here.
randi can be used to get semi-random integers. Using that you can create a 2D matrix by duplicating the array and putting them together. Thus: generate a 30x1 column and duplicate it to a 30x2 column. All rows will have the same two entries, i.e. x=y.
Noise can be added to this by creating a 30x2 matrix of random numbers, use rand for that and simply add that to the previously created matrix.
Check the documentation on svd to see how the singular-value decomposition works, it's fairly straight-forward if you know your linear algebra.
Finally for plotting you can use various tools such as image, imagesc, plot, surf and scatter, try them and see which works best for you.
Here is a quick example I made: https://saturnapi.com/fullstack/2d-points-randomly-near-line
%// Welcome to Saturn's MATLAB-Octave API.
%// Delete the sample code below these comments and write your own!'
x = 13 + 6.*rand(20,1);
y = x*0.7 + 0.5*rand(20,1);
[X,Y] = meshgrid(x,y)
figure(1);
plot(x,y,'.');
%// Print plot as PNG with resultion of 60 pixels per inch
print("MyPNG.png", "-dpng", "-r60");
I don't think I know tricks to use repmat in Matlab yet. I tried a number of combination and I am not able to achieve what I need.
I have a vector A of size 1 x 20. I just want to stack A to create 3 x 5 x 20 size matrix. Can you please help ?
A = 1:20;
reshape(repmat(A, [15, 1]), [3,5,20])
I have the following two matrices with the sizes shown:
x ---> 256x256
y ---> 65536x2
How can we equalize the sizes of those two matrices? In other words, how can we make size y equal size x? I know we can use padarray. But, how can we use it here? Wouldn't some information get lost from this equalization?
Thanks.
Have a look to Reshape. If you need help with it. Provide more informations of what you want to do.
y = reshape(y,256,256);
Use reshape function then:
reshape(y,size(x))
I have a 3D matrix called M of size <100x100x100>, so basically coordinates.
I am trying to get the array of at specific values of y. However using M(:,1,:) I get a <100x1x100> matrix whereas finding I can use M(:,:,1) and get a <100x100> matrix.
Is there an easy way to turn the <100x1x100> into a <100x100> by either isolating it a different way or using a short translation?
Thanks,
Does squeeze do what you want?
a = ones(100, 1, 100);
b = squeeze(a);
size(b) % 100x100
I have a 3d mxnxt matrix , I want to be able to extract t 2d nxm matrices.
In my case I have a 1024x1024x10 matrix and I want to have 10 images showing it to me.
This is not reshaping, I want just part of the data each time, is there a way doing it simpler that just coping member by member the data needed?
Yes, just do e.g.:
my_2d_array = my_3d_array(:,:,n);
For more info, see e.g. http://www.mathworks.com/help/techdoc/math/f1-86528.html.
as Oliver said you can use:
my_2d_array = my_3d_array(:,:,n);
You can use squeeze function to remove the 1*1 of the matrix.