Filter löschen
Filter löschen

obtain a matrix out of other matrix

3 Ansichten (letzte 30 Tage)
mehra am 24 Okt. 2019
Kommentiert: mehra am 25 Okt. 2019
I have a 1*104 matrix which ı have to create a 8*13 matrix out of it.
For one column of the final 8*13 matrix I can do the following code but how can I write one single code to get the whole matrix
for r=1:8;
This gives me the first coloumn and for the second column I can write :
for r=1:8;
and it goes the same till end...
I tried to write it in one for loop like the following but it gave me an error:
for r=1:8,c=1:12;
error : Subscript indices must either be real positive integers or logicals.
thanks for the help
  2 Kommentare
Fangjun Jiang
Fangjun Jiang am 24 Okt. 2019
Your code does not match your description. In any case, I think reshape() should help you.
mehra am 24 Okt. 2019
Maybe I can add that my 104*1 matrix is zs and I need to get zs(1), zs(14) , zs(27), zs(40), zs(53),zs(66),zs(79),zs(92) in the first column and the rest will also follow the trend to be in the 2nd to 13th columns. Please let me know if any other explanation is needed.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Fangjun Jiang
Fangjun Jiang am 24 Okt. 2019

Weitere Antworten (1)

Steven Lord
Steven Lord am 24 Okt. 2019
Bearbeitet: Steven Lord am 24 Okt. 2019
reshape your vector to be 13-by-8 then take the transpose of it.
>> x = 1:104;
>> y = reshape(x, [13 8])
>> z = y.'
You can do this in one step, but I think it's important to see the intermediate result (y) so you can see how MATLAB arranges elements. This is useful knowledge for a technique called linear indexing.


Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by