Easy Question - Set Variable to Another Variable Using sprintf
2 次查看(过去 30 天)
显示 更早的评论
I have a GUI with drop-down boxes, and based on these drop-down box values I load a specific variable (large matrix) out of my .mat file.
Here's that code which works:
STstr = get(handles.source_type,'String');
STval = get(handles.source_type,'Value');
switch STstr{STval};
case 'Single Point Source'
source_type='SingleHeightMesh';
end
SHstr = get(handles.scan_height, 'String');
SHval = get(handles.scan_height,'Value');
switch SHstr{SHval};
case '100ft'
scan_height='100';
end
filespec='%s%s';
load('MCNPdata.mat',sprintf(filespec,source_type,scan_height));
The problem is that the rest of my code uses another variable, HeightMesh which I need to assign to the large matrix I just loaded.
HeightMesh=sprintf(filespec,source_type,scan_height);
This code just assigns HeightMesh to the string value of the name of that matrix variable. How can I simply take this matrix I loaded (the name of the matrix will vary based on multiple drop-down options) and assign it to HeightMesh?
Thanks in advance.
0 个评论
采纳的回答
Shashank Prasanna
2013-1-31
编辑:Shashank Prasanna
2013-1-31
S = load('MCNPdata.mat',sprintf(filespec,source_type,scan_height));
S is a structure and one of its elements will be the matrix.
HeightMesh=S.(sprintf(filespec,source_type,scan_height));
Dynamically access the matrix as above
2 个评论
Shashank Prasanna
2013-1-31
Here is an example that works for demonstration:
S=load('accidents.mat','datasources');
HeightMesh=S.('datasources');
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 NaNs 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!