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
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개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by