Transforming Result to Meaningful Information
1 次查看(过去 30 天)
显示 更早的评论
I have a 5x4 cell array with contents as such:-
14 2 5 10
27 1 2 3
10 2 9 4
45 5 9 9
2 1 4 10
I then imported an excel file using the command:-
[~,~,A]=xlsread('filename')
The excel file has content as such:-
45 John
2 Bob
27 Alice
10 Ben
14 Peter
How can I transform the first column of the cell array to display the name instead of number (in accordance to the excel file's first column)?
0 个评论
回答(2 个)
Walter Roberson
2011-12-9
Using Andrei's variables:
[tf, idx] = ismember([M{:,1}], [A{:,1}]);
M(tf, 1) = A(idx(tf), 2);
0 个评论
Andrei Bobrov
2011-12-9
[j1,j1] = sortrows(M,1)
[i1,i1] = sortrows(A,1)
ji = sortrows([j1 i1],1)
M(:,1) = A(ji(:,2),2)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!