필터 지우기
필터 지우기

Convert vector of cells to variables

조회 수: 2 (최근 30일)
Johan
Johan 2013년 6월 17일
Hi! I'm importing data from excel and I'm finding the position of the data of interest using findstr and it works fine. My problem is that I want to get a string from the vector of cells (eg. Temperature) and assigning it a vector of digits. This is how I want it to be:
Text={'Temp', 'Humidity', 'Age'}
num=[20 0.8 2; 22 0.85 2.1; 23 0.9 2.2]
Temp=[20 22 23]
Thankful for help Regards Johan

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 6월 17일
For k=1:numel(Text)
assignin('base',Text{k},num(:,k))
end
  댓글 수: 2
Johan
Johan 2013년 6월 17일
Cheers!
Jan
Jan 2013년 6월 17일
Such remote controlled assigments have severe disadvatnages: They decrease the processing speed massively because the JIT cannot understand the program at compile time anymore. And the debugging suffers even more. Therefore I strongly recommend to follow Walter's answer.

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

추가 답변 (2개)

Walter Roberson
Walter Roberson 2013년 6월 17일

Andrei Bobrov
Andrei Bobrov 2013년 6월 17일
편집: Andrei Bobrov 2013년 6월 17일
use dataset array
Text={'Temp', 'Humidity', 'Age'}
num=[20 0.8 2; 22 0.85 2.1; 23 0.9 2.2]
d = mat2dataset(num,'VarNames',Text);
>> d.Temp
ans =
20
22
23
or
d2 = cell2struct(num2cell(num,1),Text,2);
d2.Temp
ans =
20
22
23

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by