combining variables into one matrix -from a single mat file, problem with struct to double conversion (getfield)
1 次查看(过去 30 天)
显示 更早的评论
I want to combine 254 files included in a single .mat file to produce a matrix 723 x 3127 x 254, with each variable being 723 x 3127. I have tried below, with help from another question I asked here:
clear all clc close all
load 'TJJ.mat'
% attempt to put all arcs together..
adata = NaN(723,3127,254);
for k=1:254
k
tic
% create the file name
filename = sprintf('TJJ_arc%03d.mat',k);
% load the data
data = load(filename);
d = getfield(data,'data');
% save the data
adata(:,:,k) = d;
toc
end
at the moment, I get an error with the getfield command. I want to convert the 1x1 struct file to double...
Can someone help me?
thanks in advance! Michael
1 个评论
Aurele Turnes
2014-8-5
The getfield function can be used to access a field in a structure, a fints object, or a vrnode object. If data is a structure, the code
d = getfield(data,'data');
is accessing the value of the field 'data' in the structure data, and is equivalent to doing
d = data.data;
This is what getfield does under the hood for a structure.
Is this what you are trying to do? What is the exact error message you are getting? You can check that data is a structure by typing class(data) in the MATLAB Command Window. You can also check that data has a field named 'data' by typing fieldnames(data) in the Command Window.
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!