How to 'extract" a matrix named the same way as a string in a matrix?

I am not sure even if what I asked is correct (new user), but, I have a matrix E0=[1 2] and L=['R1' 'E0']. I'd like to extract the string 'E0' from L and magicly E0 =[1 2] appears on the command window. May you help me, please?

 채택된 답변

Mischa Kim
Mischa Kim 2014년 2월 19일
편집: Mischa Kim 2014년 2월 19일
Aroldo, is this what you are looking for?
E0 = [1 2];
L = {'R1' 'E0'};
v = genvarname(L{2}); % change from L{2} to L{1} to see what happens
if exist(L{2},'var') % change from L{2} to L{1} to see what happens
eval([v '= E0'])
end
clear all

댓글 수: 1

Exactly it! Thank you, and sorry about not properly write my question.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

You want to extract 'E0' from L={'R1' 'E0'}, how? why do you wan to extract it when you already have it?
From your question you have
E0=[1 2]
L={'R1' 'E0'}
Now what do you want to do?
Extracting 'E0' from L doesn't make sens.
If you want to display E0=[1 2], just write
disp([L{2} '=[' num2str(E0) ']'])
or
disp(['E0=[' num2str(E0) ']'])

카테고리

도움말 센터File Exchange에서 Variables에 대해 자세히 알아보기

질문:

2014년 2월 19일

댓글:

2014년 2월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by