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!