Hi every body,
I have a set of data which I want to plot them. I need to extract the data of the second column and the third column correspond to the equal element in column one.
simply explaining with an example assume that my data is stored in matrix A which iis:
A=[1 5 1;...
1 8 2;...
2 3 1;...
2 10 3;...
1 7 4;...
3 1 5];
a=A(:,1);
b=A(:,2);
c=A(:,3);
the first index should be:
index1=[1 ; 1; 0; 0; 1; 0]
then:
m=b(index1);>>>>>>>[5 8 7]
t=c(index1);>>>>>>>>[1 2 4]
plot (t,m, '-');
the second index will be:
index2=[0; 0; 1; 1; 0; 0];
then:
m=b(index2);>>>>>>>[3 10]
t=c(index2);>>>>>>>>[1 3]
plot (t,m, '-');
index3=[0; 0; 0; 0; 0; 1];
then:
m=b(index3);>>>>>>>[5]
t=c(index3);>>>>>>>>[1 5]
plot (t,m, '-');
I created a following loop, but It overdo the things, this is because it iterates through the loop and each time compare the value even though the value might be already checked before. can you tell me how can I fix it?
a=A(:,1);
b=A(:,2);
t=A(:,3);
% here is to define different collor for plots from defects
c = ['r';'g';'b';'y';'m';'c'];
l = length(c);
figure
for i=1:size(a,1)
index= a(i)==a;
m=b(index);
t=t(index);
col = [c(mod(i-1,l)+1), '-'];
plot(t,m,col);
hold on
grid on
end
thanks so much,
s.
|
|
0
|
|
|
|
Reply
|
khanmoradi (52)
|
3/10/2011 7:43:06 PM |
|
A=[ 1 5 1;...
1 8 2;...
2 3 1;...
2 10 3;...
1 7 4;...
3 1 5];
a=A(:,1);
b=A(:,2);
t=A(:,3);
m = size(A,1);
[Val I J] = unique(a);
i = accumarray(J(:), (1:m)', [], @(x) {sort(x)});
c = ['r';'g';'b';'y';'m';'c'];
l = length(c);
figure
hold on
grid on
for k=1:length(i)
index=i{k};
col = [c(mod(k-1,l)+1), '-'];
plot(b(index),t(index),col);
end
% Bruno
|
|
0
|
|
|
|
Reply
|
b.luong5955 (6341)
|
3/10/2011 8:13:05 PM
|
|
|
1 Replies
14 Views
(page loaded in 0.16 seconds)
Similiar Articles: Saving data in for loop - comp.soft-sys.matlab... function in a for loop where the input data are from a 3D matrix ... Plotting result for each iteration of a for loops - comp.soft-sys ... ... The loop index is integer, the ... collecting data in loops - comp.soft-sys.matlab... the value of i as an index ... function in a for loop where the input data are from a 3D matrix with ... Plotting result for each iteration of a for loops - comp.soft-sys ... ... plot legend in for loop - comp.soft-sys.matlabOne you have this matrix you can plot outside the loop with: > subplot(311) > plot ... ve placed each curve as an array in a cell index, Y (this allows me to index through ... pcolor in Matlab - comp.soft-sys.matlabHi All, I have been trying to use pcolor for plotting ... mix two modes of pcolor. pcolor() can color a matrix ... > > I want to loop through "my other program" using param1(i ... how to choose random rows from a matrix - comp.soft-sys.matlab ...Just loop over all possible row-index pairs. Then you can use the ... rows of a data file for a 2D plot ... remove multiple rows of matrix based the value and index of row of ... Add Data to a file during each iteration - comp.soft-sys.matlab ...... use, but if the OP really needs a matrix ... Plotting result for each iteration of a for loops - comp.soft-sys ... ... task, you will add the ability to loop through ... Subscript indices must either be real positive integers or ...... for i=1, i=2, i=3 etc but if I have it done in a loop (e ... Jan, here are parts of the code: MAIN CODE: <input ... Attempted to access e(1,0); index must be a positive ... Partial Correlation Plot - comp.soft-sys.matlab... one y variable, but you can loop over the ... controlled variable) MIMO (multi input ... sure... does the bode command plot the power spectral ... Partial correlation matrix ... Draw Circle in matrix - comp.soft-sys.matlabHow do yo draw a circle in a matrix with the value at 10V?? ... First of all, you go through a useless loop over kk that ... As in Dave's code, a random permutation of the input ... Conversion to cell from double is not possible - Error - comp.soft ...We = would like to see how the plot of y ... 3Dcell(na,nt); > > > Create a for loop that uses an indexing value ... output : > > Y =3D > > > =A0 Columns 1 through 5 ... loops in matlab... in the "for" statement, and Matlab will loop through ... to perform operations on the rows of a matrix ... end >> plot(x,y) >> plot(x,y,'go') >> plot(x,y,'go',x,y) While Loops Matlab: Plotting loops, arraysMatlab: Plotting loops, arrays Math ... do this is that I want to plot the results of each loop to see how many 0, 1, 2's I have over ... pull a trick using a matrix ... 7/29/2012 5:56:44 AM
|