Compare two cell arrays of different sizes

I have two cell arrays of different sizes final_iono=68x2 cell and final_gps=288x2 cell as follows:
final_iono= Column 1('00:05','00:10','00:15'...) and Column 2 ([7.62],[7.78],[7.50]...);
final_gps= Column 1('00:05','00:20','00:35'...) and Column 2 ([109.56],[107.24],[98.22]...).
I need to compare the Column 1 of the cell array final_gps with cell array final_iono, and create a new cell array C using the following math operation:
C= Col1('00:05'), then Col2= (7.62^3/109.56) then, Col2= 4.038
So,
C= '00:05' [4.038]
Follow below an example.
Any help will be appreciate!

 Accepted Answer

[l,ii] = ismember(final_gps(:,1),final_iono(:,1));
C = cat(1,final_gps{l,2}).^3./cat(1,final_iono{ii(l),2});
ADD
l = ismember(final_gps(:,1),final_iono(:,1));
C = cat(1,final_gps{l,2}).^3./cat(1,final_iono{:,2});

6 Comments

Hi Andrei! The ismember and cat command worked perfectly, but I had to change the second line to read all rows, I did:
C=cat(1,final_gps{:,2}).^3./cat(1,final_iono{ii(:),2});
but appears the following error:Subscript indices must either be real positive integers or logicals. I need also the program shows the C matrix as previous figure (HH:MM)col1 and (value)col2. Can you help me again? Thanks in advance
Andrei, only the value 7.621 (final_gps at 00:05) is taking part of the math operation. For example, when final_gps at 00:20 the value 7.1643 must divided by 107.2476 as shows on figure above. I tried to change the line into C=cat(1,final_gps{ii,2})..., but it didn't work.
Code in block ADD working? Please attach file with you data (mat - file)
It worked Andrei... Thanks a lot.
chocho
chocho on 10 Mar 2017
Edited: chocho on 10 Mar 2017
Hi @Andrei Bobrov friend, i have the same case but cell inside cell like cell array1 size 200*1 (column vector array:row=200 and col=1) but inside each row also 1*3 cell .
how could i get access the those elements using a loop?

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!