Variable Cell Array to Dynamic Structure
1 回表示 (過去 30 日間)
古いコメントを表示
Marguerite Kennish
2020 年 7 月 2 日
回答済み: Marguerite Kennish
2020 年 7 月 2 日
Hello!
I am working on a project that opens files into a dynamic structure using the uigetfile().
The code uses boolean statements to perform calculations on the data from several different file types using variable naming convetions 'extens', 'frac', 'DAQ, 'MTS', as the suffixes associaed with each branch.
The code then creates a cell array of the variables using whos, uses a for loop to cycle through the aray, convert each cell to a string, then builds a second dynamic structure for dataSummary, which will eventually be exported in an excel document.
Currently, the structure's value is associated to the string of text from the variable name cell array. I need a way to replace the val_i string with the actual values associated with the variable the string matches.
Any help or pointers would be greatly apreciated!
--PS I know that dynamic variable creation is a big no no , that is why I used the dynamic structure/fieldnames creation as recmended here
my code:
% will load over 50 variables that need to be sorted
all_current_variables = who;
for i=1:length(all_current_variables)
%converts to string
val_i=all_current_variables{i,1};
% searches string for the section of the new structure
% the variable belongs in
if strfind(val_i,'extens')==1
%sorts into branch dictated by the suffix then uses the val_i to creat
%new field,
DataSummary.DIC_Extens.(val_i)=...
val_i;
% issue is here I want the field to be associated with the
% values of the varrable
% currently is only associating with the string that
% matchesthe variables name in the workspace
elseif strfind(val_i,'frac')==1
DataSummary.DIC_Fracbox.(val_i)=val_i;
elseif strfind(val_i,'DAQ')==1
DataSummary.DAQ.(val_i)=val_i;
elseif strfind(val_i,'MTS')==1
DataSummary.MTS.(val_i)=val_i;
end
end
2 件のコメント
採用された回答
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Structures についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!