This question already has answers here:
how to replicate an array
(4 answers)
Closed 8 years ago.
Could you help me please to repeat matrix. for example if I have matrix(A) and I want to create a big matrix(B) contains three matrices of matrix(A) in the row and two matrices in the column.
The MATLAB function repmat does exactly what you need:
B = repmat(A,3,2);
For more details see the MATLAB documentation
In MatLab, you want to use repmat().
In Python, use the Numpy function, tile(a, (m, n)).
You should check out this post: https://stackoverflow.com/a/1724410/515559
Related
This question already has answers here:
How to automatically create variables which are column extracts from a matrix
(4 answers)
MATLAB - Need to split a Matrix into column variables with names sourced from another matrix?
(3 answers)
Closed 5 years ago.
I have created a color map:
Color map=jet(40)
From this I want to use a loop to extract each row of the colormap as 40 separate matrix (vector) with the title rgb1-rgb40. How to do this?
You can use eval to execute a dynamically created string as follow:
map=jet(40)
for i=1:size(map, 1)
eval(['rgb', num2str(i), '= map(', num2str(i), ', :)']);
end
Warning: Note that converting your matrix to 40 vectors in this way is probably not the most elegant solution for what you try to obtain. For more information, see Alternatives to the eval Function.
This question already has an answer here:
Select portion of timeseries
(1 answer)
Closed 7 years ago.
I have a Matlab timeseries object with content
Time: [1000x1 double]
Data: [1000x1 double].
How can I select the first n (f.e. 300) points of the timeseries? I would like to find a function that allows me to write timeseries2=timeseries1(1:300), rather than
timeseries2.Data=timeseries1.Data(1:300)
timeseries2.time=timeseries1.time(1:300)
I have looked in the Matlab help function, but could not find it yet.
ts2=ts.getsamples(1:300)
documented here
This question already has answers here:
Element-wise array replication in Matlab
(7 answers)
Closed 7 years ago.
i have an array in matlab software like this:
X=[x1,x2,x3];
And, I want to change this array to be like this:
X=[x1,x1,x2,x2,x3,x3];
Is there any command for doing this work in the simplest way ?
Use reshape and repmat like this
a=[1 2 3];reshape(repmat(a, 2, 1), 1, [])
repmat creates the amount of entries and reshape orders it as you asked.
This question already has an answer here:
How to store this structure (list of lists of integers) in Matlab?
(1 answer)
Closed 7 years ago.
I want to create list of the following type:
[ [1,2,3], [5,6] , [1,2,4,6,7,89,9,74,4]]
But whenever I do, matlab automatically concatenates the list. Can anyone help me out?
What you want is called cell array, you can create one by doing:
A = {[1,2,3], [5,6], [1,2,4,6,7,89,9,74,4]};
To access cell elements you have to use the {} operator. As #TroyHaskin said, you can find a most complete answer here
This question already has answers here:
Efficient Implementation of `im2col` and `col2im`
(2 answers)
Closed 7 years ago.
example: I have an image,it's size 512X512pixel,then i have splited it into 8x8 blocks.Now i would have 64x64 blocks.Now how to rearrange each block 8x8 into column vector so that the dimension would be 64x4096pixel without inbuilt function "im2col".please help me out.
Thanks.
x=rand(512,512);
xi=mat2cell(x,8*ones(1,64),8*ones(1,64));
xii=cellfun(#(x)reshape(x,1,64),xi,'UniformOutput',false);
y=cell2mat(xii);