Using cellfun to pull information
2 ビュー (過去 30 日間)
古いコメントを表示
Hopefully I can explain this!
I have the following code:
clear;
clc;
%--------------------------------------------------------------------------
% Table 1
Color1 = ["Blue"; "Orange";"Purple";"Blue";"Fuschia";"Red"];
LiscensePlate1 = [12569;12897;56783;45231;78999;99999];
t1first = datetime(2021,1,1,0,0,0);
t2first = datetime(2021,1,1,3,0,0);
tfirst = t1first:minutes(35):t2first;
tfirst=tfirst';
cars1 = table(Color1,LiscensePlate1,tfirst);
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
% Table 2
Color2 = ["Blue"; "Orange";"Purple";"Blue";"Fuschia";"Red"];
LiscensePlate2 = [88888;12897;77777;45231;88999;99999];
t1second = datetime(2022,1,1,2,0,0);
t2second = datetime(2022,1,1,5,0,0);
tsecond = t1second:minutes(35):t2second;
tsecond=tsecond';
cars2 = table(Color2,LiscensePlate2,tsecond);
%--------------------------------------------------------------------------
For this example, say I am out watching cars on my street corner on two different days and I write down the above information (color, liscense plate number, and the time I saw the car).
Is there any way to use cellfun to search between the two tables and see if any of the liscense plate numbers match? If they match, how would I then pull the time I saw the cars and see when the difference is between the time I first saw the car and the second?
I know with a table this small and I could look for the matching liscense plates easily but I am actually dealing with a larger data set and would need this automated (cellfun) if possible!
Thank you in advance for all of your help!
0 件のコメント
採用された回答
Jan
2022 年 7 月 18 日
編集済み: Jan
2022 年 7 月 18 日
cellfun works on cell arrays, as the name says. You are working with tables. So this command does not match at all.
Color1 = ["Blue"; "Orange";"Purple";"Blue";"Fuschia";"Red"];
LiscensePlate1 = [12569;12897;56783;45231;78999;99999];
t1first = datetime(2021,1,1,0,0,0);
t2first = datetime(2021,1,1,3,0,0);
tfirst = t1first:minutes(35):t2first;
tfirst=tfirst';
cars1 = table(Color1,LiscensePlate1,tfirst)
% Table 2
Color2 = ["Blue"; "Orange";"Purple";"Blue";"Fuschia";"Red"];
LiscensePlate2 = [88888;12897;77777;45231;88999;99999];
t1second = datetime(2022,1,1,2,0,0);
t2second = datetime(2022,1,1,5,0,0);
tsecond = t1second:minutes(35):t2second;
tsecond=tsecond';
cars2 = table(Color2,LiscensePlate2,tsecond);
[match, index] = ismember(cars1.LiscensePlate1, cars2.LiscensePlate2)
cars1(match, :)
cars2(index(match), :)
By the way, the word is "license", not "liscense".
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Data Type Conversion についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!