Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

variables form strucutre

조회 수: 1 (최근 30일)
Richard
Richard 2012년 2월 20일
마감: MATLAB Answer Bot 2021년 8월 20일
I have the following example which expresses the type of problem that I'm trying to solve:
clear all
textdata = {'DateTime','St','uSt','Ln','W'};
data = rand(365,4);
Final = struct('data',data,'textdata',{textdata})
clear textdata data
From this, Final.data contains values which correspond to the headings in Final.textdata excluding the first ('DateTime') thus Final.data(:,1) corresponds to the heading 'St'... and so on. What I'm trying to do is to create a variable in the workspace for each of these vectors. So, I would have a variable for St, uSt, Ln, and W in the workspace with the corresponding values given in Final.data.
How could this be done?
  댓글 수: 1
Oleg Komarov
Oleg Komarov 2012년 2월 20일
format your question please: http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup

답변 (1개)

Andrei Bobrov
Andrei Bobrov 2012년 2월 20일
EDIT after comment from Iestyn
d = Final.data;
k = [Final.textdata(2:end);mat2cell(d,size(d,1),ones(size(d,2),1))];
out = struct(k{:});
  댓글 수: 1
Richard
Richard 2012년 2월 20일
this works fine like this but what if my data is stored as it is in 'Final', i.e. a structure which has an array (data) and a cell array (textdata)?

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by