I have a datasetX=[12 25 36 47 58 69;34 56 78 90 12 34 ;00 12 89 36 87 56 ]Y=[89 36 87 56 00 25;25 36 47 87 56 25 ;89 78 45 23 56 99 ]now i want to add first column of X any Y and store it in separate variables for each columni have 100 rows
MATLAB: Looping for a program
looping
Related Solutions
Something like this?
y = x;y(1,end+1) = 1;for i = 2:size(y,1) if y(i,4) == y(i-1,4) y(i,end) = y(i-1,end) + 1; else y(i,end) = 1; endend
**EDIT: Fixed a typo, should work now.
So I think this might be what you're looking for. I commented out the 'i' redefinition at the very bottom and added 'figure' but to answer the coloring question I recommend using the mod (for modulus) command. If you specify
color{mod(i-1,4)+1}
the values, for i=1:8 for example, will go:
color{1}color{2}color{3}color{4}color{1}color{2}color{3}color{4}
and the pattern will keep repeating for varying 'i' definitions. Here is the modified code:
AOI=[0 0 0 0 0 0 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 3 3 3 3 3 3 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 8 8 8 8 8 8];row1=[35 35 35 35 36 36.5 37 35 37 35 36 37 36 35 37 34 34 35 36 36 36 37 37 37 38 38 34 34 35 35 35 35 35 35 35 35 35 36 36.5 37 35 37 36 35 37 34 34 35 36 36 36 37 37 37 38 38 34 34 35 35 35 35 35];col1= [56 57 57 58 56 57 56 56 56 57 45 45 46 46 46 44 45 45 46 46 47 47 48 48 46 46 45 46 45 46 47 56 56 57 57 58 56 57 56 56 56 57 45 45 46 46 46 44 45 45 46 46 47 47 48 48 46 46 45 46 45 46 47];row2=[35 35 35 35 36 36.5 37 35 37 35 36 37 36 35 37 34 34 35 36 36 36 37 37 37 38 38 34 34 35 35 35 35 35 35 35 35 35 36 36.5 37 35 37 36 35 37 34 34 35 36 36 36 37 37 37 38 38 34 34 35 35 35 35 35];col2= [56 57 57 58 56 57 56 56 56 57 45 45 46 46 46 44 45 45 46 46 47 47 48 48 46 46 45 46 45 46 47 56 56 57 57 58 56 57 56 56 56 57 45 45 46 46 46 44 45 45 46 46 47 47 48 48 46 46 45 46 45 46 47];row3=[35 35 35 35 36 36.5 37 35 37 35 36 37 36 35 37 34 34 35 36 36 36 37 37 37 38 38 34 34 35 35 35 35 35 35 35 35 35 36 36.5 37 35 37 36 35 37 34 34 35 36 36 36 37 37 37 38 38 34 34 35 35 35 35 35];col3= [56 57 57 58 56 57 56 56 56 57 45 45 46 46 46 44 45 45 46 46 47 47 48 48 46 46 45 46 45 46 47 56 56 57 57 58 56 57 56 56 56 57 45 45 46 46 46 44 45 45 46 46 47 47 48 48 46 46 45 46 45 46 47];row4=[25 25 25 25 26 26.5 27 25 27 25 26 27 26 25 27 24 24 25 26 26 26 27 27 27 28 28 24 24 25 25 25 25 25 25 25 25 25 26 26.5 27 25 27 26 25 27 24 24 25 26 26 26 27 27 27 28 28 24 24 25 25 25 25 25];col4= [56 57 57 58 56 57 56 56 56 57 45 45 46 46 46 44 45 45 46 46 47 47 48 48 46 46 45 46 45 46 47 56 56 57 57 58 56 57 56 56 56 57 45 45 46 46 46 44 45 45 46 46 47 47 48 48 46 46 45 46 45 46 47];row5=[35 35 35 35 36 36.5 37 35 37 35 36 37 36 35 37 34 34 35 36 36 36 37 37 37 38 38 34 34 35 35 35 35 35 35 35 35 35 36 36.5 37 35 37 36 35 37 34 34 35 36 36 36 37 37 37 38 38 34 34 35 35 35 35 35];col5= [66 67 67 68 66 67 66 66 66 67 65 65 66 66 66 64 65 65 66 66 67 67 68 68 66 66 65 66 65 66 67 66 66 67 67 68 66 67 66 66 66 67 65 65 66 66 66 64 65 65 66 66 67 67 68 68 66 66 65 66 65 66 67];row6=[35 35 35 35 36 36.5 37 35 37 35 36 37 36 35 37 34 34 35 36 36 36 37 37 37 38 38 34 34 35 35 35 35 35 35 35 35 35 36 36.5 37 35 37 36 35 37 34 34 35 36 36 36 37 37 37 38 38 34 34 35 35 35 35 35];col6= [56 57 57 58 56 57 56 56 56 57 45 45 46 46 46 44 45 45 46 46 47 47 48 48 46 46 45 46 45 46 47 56 56 57 57 58 56 57 56 56 56 57 45 45 46 46 46 44 45 45 46 46 47 47 48 48 46 46 45 46 45 46 47];row7=[35 35 35 35 36 36.5 37 35 37 35 36 37 36 35 37 34 34 35 36 36 36 37 37 37 38 38 34 34 35 35 35 35 35 35 35 35 35 36 36.5 37 35 37 36 35 37 34 34 35 36 36 36 37 37 37 38 38 34 34 35 35 35 35 35];col7= [56 57 57 58 56 57 56 56 56 57 45 45 46 46 46 44 45 45 46 46 47 47 48 48 46 46 45 46 45 46 47 56 56 57 57 58 56 57 56 56 56 57 45 45 46 46 46 44 45 45 46 46 47 47 48 48 46 46 45 46 45 46 47];row8=[2:2:126];col8= [56 57 57 58 56 57 56 56 56 57 45 45 46 46 46 44 45 45 46 46 47 47 48 48 46 46 45 46 45 46 47 56 56 57 57 58 56 57 56 56 56 57 45 45 46 46 46 44 45 45 46 46 47 47 48 48 46 46 45 46 45 46 47];coord=[2:2:126];times=[1:63];AOI_unique=unique(AOI);num_AOI=length(AOI_unique);colors={'r' 'g' 'b' 'c' };%while num_AOI>length(colors)
figurehplt=plot(times,coord, 'DisplayName', 'coord\_pos\_sibs\_xfpi'); hold on hleg=legend('-DynamicLegend'); set(hleg, 'FontSize',10); grid on datetick('x','HH:MM:SS', 'keeplimits') title('Position of SIBS on FPI') xlim([min(times), max(times)]) xlabel('Time (UT)'); ylabel('Value'); hold onfor i=1:length(AOI_unique) if AOI_unique(i)==1 %%Plot
hplt=plot(times, col1, colors{mod(i-1,4)+1}, 'DisplayName', 'column 1'); hold on hplt=plot(times, row1, 'c--', 'DisplayName', 'row 1'); hold on hleg=legend('-DynamicLegend'); set(hleg, 'FontSize',10); grid on elseif AOI_unique(i)==2 %%Plot hplt=plot(times, col2, colors{mod(i-1,4)+1}, 'DisplayName', 'column 2'); hold on hplt=plot(times, row2, 'g--', 'DisplayName', 'row 2'); hold on hleg=legend('-DynamicLegend'); set(hleg, 'FontSize',10); grid on elseif AOI_unique(i)==3 %%Plot hplt=plot(times, col3, colors{mod(i-1,4)+1}, 'DisplayName', 'column 3'); hold on hplt=plot(times, row3, 'b--', 'DisplayName', 'row 3'); hold on hleg=legend('-DynamicLegend'); grid on elseif AOI_unique(i)==4 %%Plot hplt=plot(times, col4, colors{mod(i-1,4)+1}, 'DisplayName', 'column 4'); hold on hplt=plot(times, row4, 'r--', 'DisplayName', 'row 4'); hold on hleg=legend('-DynamicLegend'); set(hleg, 'FontSize',10); grid on elseif AOI_unique(i)==5 %%Plot hpltA=plot(times, col5, colors{mod(i-1,4)+1}, 'DisplayName', 'column 5'); hold on hplt=plot(times, row5, 'c--', 'DisplayName', 'row 5'); hold on hleg=legend('-DynamicLegend'); set(hleg, 'FontSize',10); grid on elseif AOI_unique(i)==6 %%Plot hplt=plot(times, col6, colors{mod(i-1,4)+1}, 'DisplayName', 'column 6'); hold on hpltA=plot(times, row6, 'g--', 'DisplayName', 'row 6'); hold on hleg=legend('-DynamicLegend'); set(hleg, 'FontSize',10); grid on elseif AOI_unique(i)==7 %%Plot hplt=plot(times, col7, colors{mod(i-1,4)+1}, 'DisplayName', 'column 7'); hold on hplt=plot(times, row7, 'b--', 'DisplayName', 'row 7'); hold on hleg=legend('-DynamicLegend'); set(hleg, 'FontSize',10); grid on elseif AOI_unique(i)==8 %%Plot hplt=plot(times, col8, colors{mod(i-1,4)+1}, 'DisplayName', 'column 8'); hold on hplt=plot(times, row8, 'r--', 'DisplayName', 'row 8'); hold on hleg=legend('-DynamicLegend'); set(hleg, 'FontSize',10); grid on end% i=i+1;
end
Best Answer