Info
This question is closed. Reopen it to edit or answer.
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 view (last 30 days)
Show older comments
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 Comments
Answers (1)
Dishant Arora
on 6 Apr 2014
str = {'user1', 'user2', 'user3'};
cordinates = {[1,2], [2,4], [4,8]};
cellfun(@(x,y) assignin('base', eval('x'), y), str, cordinates)
2 Comments
Jeff
on 6 Apr 2014
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
on 6 Apr 2014
Edited: Dishant Arora
on 7 Apr 2014
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.
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!