Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

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],....,u​ser50=[x50​,y50].

1 vue (au cours des 30 derniers jours)
Meme
Meme le 6 Avr 2014
Clôturé : MATLAB Answer Bot le 20 Août 2021
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

Réponses (1)

Dishant Arora
Dishant Arora le 6 Avr 2014
str = {'user1', 'user2', 'user3'};
cordinates = {[1,2], [2,4], [4,8]};
cellfun(@(x,y) assignin('base', eval('x'), y), str, cordinates)
  2 commentaires
Jeff
Jeff le 6 Avr 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
Dishant Arora le 6 Avr 2014
Modifié(e) : Dishant Arora le 7 Avr 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.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by