Managing Matrix Content Using Loop ?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
e.g i have variable data that containt matrix like these ;
a1 b1 c1
a2 b2 c2
a3 b3 c3
and i wanted it stored like :
a1
a2
a3
b1
b2
b3
c1
c2
c3
I use looping
inc=1;
[s1,s2]=size(data);
for x=1:s2
for y=1:s1
dataStored(inc)=data(y,x);
inc=inc+1;
end
end
It's work, but on a very large amount of data like data < 512x3671 int 16 > take endless time to wait. Is there any way simple to do that? Or maybe my code is wrong ?
0 Kommentare
Akzeptierte Antwort
Cedric
am 24 Mär. 2013
Bearbeitet: Cedric
am 24 Mär. 2013
>> A = magic(3) % Just an example..
A =
8 1 6
3 5 7
4 9 2
>> v = A(:) % Read A as a column vector (linear indexing).
v =
8
3
4
1
5
9
6
7
2
6 Kommentare
Cedric
am 25 Mär. 2013
Bearbeitet: Cedric
am 25 Mär. 2013
Well, [b;0] adds only one 0 element to b and look at the size of each of your vectors.. the size difference is much greater than just one element. It is 150 actually. Now if it is really meaningful to add 150 0's to b, you can do it as follows:
bext = [b; zeros(150,1)] ;
c = [a, bext] ;
but as far as I'm concerned, it would be a good investment of your time to read a tutorial, so you understand at least the basics about array manipulation in MATLAB.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing 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!