How to find data from different matrix accordance to a treaty

1 vue (au cours des 30 derniers jours)
Thar
Thar le 17 Mar 2015
Modifié(e) : wil le 21 Mar 2015
Hi all! Please help!
I have two matrix with different dimensions and I want to plot some data from first and some data from the second accordance to a treaty. First matrix is:
8 10,0605560000000 2,19400000000000 318,300000000000 8,41918983333333
8 10,5166670000000 2,16400000000000 317,800000000000 8,43819445833333
9 8,05666700000000 3,13100000000000 320,500000000000 9,33569445833333
9 9,05444400000000 2,44200000000000 321,700000000000 9,37726850000000
9 10,0169440000000 2,19000000000000 320,500000000000 9,41737266666667
9 10,4705560000000 2,15500000000000 320,700000000000 9,43627316666667
10 10,8983330000000 2,15300000000000 345,600000000000 10,4540972083333
10 12,6902780000000 2,73300000000000 334,600000000000 10,5287615833333
11 8,00638900000000 3,15900000000000 306,700000000000 11,3335995416667
11 8,71111100000000 2,59000000000000 306,800000000000 11,3629629583333
11 9,05722200000000 2,42000000000000 306,500000000000 11,3773842500000
11 9,19666700000000 2,36600000000000 306,800000000000 11,3831944583333
11 9,92138900000000 2,18400000000000 305,800000000000 11,4133912083333
11 10,2961110000000 2,14300000000000 307,900000000000 11,4290046250000
14 9,37944400000000 2,27200000000000 320,200000000000 14,3908101666667
14 9,55444400000000 2,22400000000000 318,300000000000 14,3981018333333
16 10,9255560000000 2,08300000000000 343,600000000000 16,4552315000000
16 12,8616670000000 2,71900000000000 334 16,5359027916667
17 8,00500000000000 3,05900000000000 315,200000000000 17,3335416666667
17 8,53833300000000 2,61400000000000 313,300000000000 17,3557638750000
17 8,88444400000000 2,42200000000000 315,300000000000 17,3701851666667
17 9,02444400000000 2,35900000000000 312 17,3760185000000
The second matrix is:
7 13,2502780000000 3,32706700000000 216,616500000000 7,55209491666667
8 10,1752780000000 2,18026800000000 318,552446000000 8,42396991666667
8 10,3502780000000 2,16782900000000 311,812207000000 8,43126158333333
8 10,5597220000000 2,16194100000000 322,855557000000 8,43998841666667
8 10,7558330000000 2,16519900000000 326,371126000000 8,44815970833333
8 10,9433330000000 2,17629400000000 322,198083000000 8,45597220833333
8 11,1275000000000 2,19501000000000 326,766784000000 8,46364583333333
9 9,64222200000000 2,25401500000000 329,669721000000 9,40175925000000
9 9,83694400000000 2,21544900000000 331,429023000000 9,40987266666667
9 10,2577780000000 2,16408400000000 334,167393000000 9,42740741666667
9 12,6952780000000 2,75292100000000 319,587539000000 9,52896991666667
10 13,9086110000000 4,37976100000000 197,899461000000 10,5795254583333
11 7,75722200000000 3,46624100000000 197,799138000000 11,3232175833333
11 8,25666700000000 2,90756100000000 219,678581000000 11,3440277916667
11 9,05055600000000 2,42024800000000 250,809758000000 11,3771065000000
11 11,4597220000000 2,21250200000000 292,723255000000 11,4774884166667
12 8,76305600000000 2,54592200000000 230,458298000000 12,3651273333333
12 8,97388900000000 2,44217200000000 227,875052000000 12,3739120416667
12 9,20166700000000 2,35097600000000 270,648275000000 12,3834027916667
12 9,43805600000000 2,27545700000000 287,292242000000 12,3932523333333
12 9,66972200000000 2,21784400000000 263,244168000000 12,4029050833333
13 11,0405560000000 2,12788200000000 342,286940000000 13,4600231666667
13 12,0719440000000 2,35468200000000 333,077368000000 13,5029976666667
13 12,2405560000000 2,42261700000000 339,119709000000 13,5100231666667
14 11,3652780000000 2,15610300000000 247,436415000000 14,4735532500000
14 11,5663890000000 2,19384600000000 279,951366000000 14,4819328750000
14 11,7661110000000 2,24181400000000 270,288234000000 14,4902546250000
14 11,9855560000000 2,30795500000000 241,350318000000 14,4993981666667
16 12,4169440000000 2,44870200000000 232,896976000000 16,5173726666667
16 13,1205560000000 2,92910800000000 238,656026000000 16,5466898333333
16 13,3555560000000 3,17478800000000 214,067701000000 16,5564815000000
16 13,8230560000000 3,88352000000000 218,751504000000 16,5759606666667
17 7,64722200000000 3,51006600000000 213,658530000000 17,3186342500000
17 7,87444400000000 3,20061400000000 194,116288000000 17,3281018333333
First column is the day. I want to plot for the same day from two matrix the columns 4&5.
Thank you.
  2 commentaires
Geoff Hayes
Geoff Hayes le 18 Mar 2015
Thodoris - rather than pasting your two matrices into your question body (instead attach as text files) why not just describe them. What are the dimensions of each matrix? What do the columns mean? How do you expect to plot all of the data from columns four and five for the same day? For example, if the day is 8, what do you want to do?
Thar
Thar le 19 Mar 2015
Modifié(e) : Thar le 20 Mar 2015
For example, if the day is 8, I'd like to take the data from columns 4&5 from two matrices and plot. However, the data from two matrices may not have the same dimensions. The first matrix may have 7 lines and the second matrix 16 lines. Also, the one matrix may not have some days.

Connectez-vous pour commenter.

Réponses (1)

wil
wil le 20 Mar 2015
Modifié(e) : wil le 21 Mar 2015
You can use find() on the first column to get the row indexes of the rows you want to plot.
Say your matrices are A and B, then you can do
idx_a = find(A(:,1) == day);
idx_b = find(B(:,1) == day);
toplot_a = A(idx_a,4:5);
toplot_b = B(idx_b,4:5);
The toplot variables will by n-by-2 matrices of your values for that day (from the 4th and 5th column), and empty if there are no values for that day.
Wil
  2 commentaires
Thar
Thar le 20 Mar 2015
my matrices have days 1:365.Some days are missing. If i write
for i=1:365
day=i;
idx_a = find(A(:,1) == day);
idx_b = find(B(:,1) == day);
end
i take the message:
Index exceeds matrix dimensions.
wil
wil le 21 Mar 2015
The only indexing is in A(:,1) and B(:,1), but there shouldn't be a problem with that if both A and B are non-empty (since they will at least be 1-by-1).
I did notice a typo in my original code:
toplot_b = A(idx_b,4:5);
should actually be
toplot_b = B(idx_b,4:5);
so if you copied that, this could be the course of the indexing error. I have corrected the original code sample now as well.

Connectez-vous pour commenter.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by