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!