Info
この質問は閉じられています。 編集または回答するには再度開いてください。
if i have 2 cell arrays one containing user names and the other containing coordinate. how can i make the first name equals the first coordinate and so on ? for example i want user1=[x1,y1],....,user50=[x50,y50].
1 回表示 (過去 30 日間)
古いコメントを表示
if i have 2 cell arrays one containing user names and the other containing coordinate. how can i make the first name equals the first coordinate and so on ? for example i want user1=[xR1 yR1],....,user50=[xR50 yR50],so when i want to use coordinate [xR1 yR1] i call user1.
user = cell(50,50);
name=cell(size(user,2),1);
for i=1:size(user,2)
name{i}=['user ',num2str(i)];
end
users = cell(50, 1);
for i=1:50
users{i} =[xR(i) yR(i)];
end
0 件のコメント
回答 (1 件)
Dishant Arora
2014 年 4 月 6 日
str = {'user1', 'user2', 'user3'};
cordinates = {[1,2], [2,4], [4,8]};
cellfun(@(x,y) assignin('base', eval('x'), y), str, cordinates)
2 件のコメント
Jeff
2014 年 4 月 6 日
Hi can I ask for some further description of the cellfun; I get that it allows to pass a function in a cell array;
Can you explain how to interpret @(x,y)
assignin('base', eval('x'), y) -- I get you are assiging the value of y to x but can you explain what 'base' means and why you use the eval('x')??
Thanks a bunch
Dishant Arora
2014 年 4 月 6 日
編集済み: Dishant Arora
2014 年 4 月 7 日
Cellfun evaluate the function specified by function handle(see the link below) to the contents of cell array.
x and y are input parameters to anonymous functions. See this for detail: anonymous functions. And base here refers to the base workspace, check out documentation.
この質問は閉じられています。
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!