Error: "Cell contents assignment to a non-cell array object."

5 views (last 30 days)
Hello,
I am getting the error "Cell contents assignment to a non-cell array object" on a single line which is attempting to assign a variable into a previously created cellarray. The code does this many times, however, it is only getting stuck at this one and I can't figure out why. I have checked the brackets used and some other tips I found in the forum.
Thanks for the help. The code is below. The error is on line 135 (Glx_AlphaTissCorr{count} = Glx_AlphaTissCorr;)
source_path = 'B:\BBA\Gannet\Tests\Test_batchAllSteps\Test_batchWithWater_7.26.18\GannetQuantify_output'; %where we are pulling data (.mat files) from
final_path = 'B:\BBA\Gannet\Tests\Test_batchAllSteps\Test_batchWithWater_7.26.18\GannetQuantify_output'; %where to output excel file
keyword = 'MRS_struct';
%need to declare variables/arrays as zero so we can add to them in loops
cd(source_path)
%%Make empty arrays with N_max, 1 dimension to hold N data.
%1, N_max is row, N_max,1 is column
N_max = 100;
count = 0;
MAT_filename_cellarray = cell(N_max,1);
%Empty cell arrays here that we will fill later
%Data input in comment to right of empty array line below
%GABA cell arrays
GABACr_cellarray = cell(N_max,1); %from output: ConcCr
GABAIU_cellarray = cell(N_max,1);%from output: ConcIU
GABAFitError_cellarray = cell(N_max,1);%from output: FitError
GABA_CSFCorr_cellarray = cell(N_max, 1);%from output: ConcIU_CSFCorr
GABA_TissCorr_cellarray = cell(N_max, 1);%from output: ConcIU_TissCorr
GABA_AlphaTissCorr_cellarray = cell(N_max, 1); %from output: ConcIU_AlphaTissCorr
GABA_AlphaTissCorr_GrpNorm_cellarray = cell(N_max, 1); %from output: ConcIU_AlphaTissCorr_GrpNorm
%Glx cell arrays
GlxCr_cellarray = cell(N_max,1); %from output: ConcCr
GlxIU_cellarray = cell(N_max,1); %from output: ConcIU
GlxFitError_cellarray = cell(N_max,1); %from output: FitError
Glx_CSFCorr_cellarray = cell(N_max, 1); %from output: ConcIU_CSFCorr
Glx_TissCorr_cellarray = cell(N_max, 1); %from output: ConcIU_TissCorr
Glx_AlphaTissCorr_cellarray = cell(N_max, 1); %from output: ConcIU_AlphaTissCorr
Glx_AlphaTissCorr_GrpNorm_cellarray = cell(N_max, 1); %from output: ConcIU_AlphaTissCorr_GrpNorm
%Tissue composition cell arrays
GMFra_cellarray = cell(N_max, 1); %from output: GMfra
WMFra_cellarray = cell(N_max, 1); %from output: WMfra
CSFfra_cellarray = cell(N_max, 1); %from output: CSFfra
%output_xls_filename = 'Gannet_MAT_Output';
%%Read Data + set variables to load into arrays / export at end
display (' look for MAT files in Quantify folder');
MAT_file_location = dir([source_path, '/*.mat']);%list all conent from location of MAT files
for i = 1: length(MAT_file_location);
%%%Suggestion from forum. Can use instead of strfind
% F = sprintf('*%s*.mat', keyword);
% S = dir(fullfile(source_path, F));
% for k = 1:numel(S)
% tmp_ = load(fullfile(F,S(k).name));
if(strfind(MAT_file_location(i).name, keyword)); %if file has MRS_struct in name
%load mat files to array- loading file we found at top of loop with
%keyword etc
tmp = load(MAT_file_location(i).name); % getting the name and ext. of file "MRS_struct.mat"
% tmp is now MRS_struct file
count = count + 1;
display ('Look for data from MRS_struct');
%dont put these values in '' or it will be string, this gives data
display ('Getting GABA data from MRS_struct');
%GABA Data from MRS_struct-- here we are getting values from MRS
%struct and assigning to variables
GABACr = tmp.MRS_struct.out.vox1.GABA.ConcCr(i);
GABAIU = tmp.MRS_struct.out.vox1.GABA.ConcIU(i);
GABAFitError = tmp.MRS_struct.out.vox1.GABA.FitError(i);
GABA_CSFcorr = tmp.MRS_struct.out.vox1.GABA.ConcIU_CSFcorr(i);
GABA_TissCorr = tmp.MRS_struct.out.vox1.GABA.ConcIU_TissCorr(i);
GABA_AlphaTissCorr = tmp.MRS_struct.out.vox1.GABA.ConcIU_AlphaTissCorr(i);
GABA_AlphaTissCorr_GrpNorm = tmp.MRS_struct.out.vox1.GABA.ConcIU_AlphaTissCorr_GrpNorm(i);
display ('Getting Glx data from MRS_struct');
%Glx Data from MRS_struct
GlxCr = tmp.MRS_struct.out.vox1.Glx.ConcCr(i);
GlxIU = tmp.MRS_struct.out.vox1.Glx.ConcIU(i);
GlxFitError = tmp.MRS_struct.out.vox1.Glx.FitError(i);
GlxIU_CSFcorr = tmp.MRS_struct.out.vox1.Glx.ConcIU_CSFcorr(i);
Glx_TissCorr = tmp.MRS_struct.out.vox1.Glx.ConcIU_TissCorr(i);
Glx_AlphaTissCorr = tmp.MRS_struct.out.vox1.Glx.ConcIU_AlphaTissCorr(i);
Glx_AlphaTissCorr_GrpNorm = tmp.MRS_struct.out.vox1.Glx.ConcIU_AlphaTissCorr_GrpNorm(i);
display ('Getting Tissue data from MRS_struct');
%Tissue Concentration Data from MRS_struct
GMFra = tmp.MRS_struct.out.vox1.tissue.GMfra(i);
WMFra = tmp.MRS_struct.out.vox1.tissue.WMfra(i);
CSFfra = tmp.MRS_struct.out.vox1.tissue.CSFfra(i);
%Here we are assigning above data to empty arrays created earlier
%We will then export them below
display ('Assigning data to arrays');
%Loading GABA variables/data into arrays
MAT_filename_cellarray{count} = MAT_file_location(i).name;
GABACr_cellarray{count} = GABACr;
GABAIU_cellarray{count} = GABAIU;
GABAFitError_cellarray{count} = GABAFitError;
GABA_CSFCorr_cellarray{count} = GABA_CSFcorr;
GABA_TissCorr_cellarray{count} = GABA_TissCorr;
GABA_AlphaTissCorr_cellarray{count} = GABA_AlphaTissCorr;
GABA_AlphaTissCorr_GrpNorm_cellarray{count} = GABA_AlphaTissCorr_GrpNorm;
%Loading Glx variables/data into arrays
GlxCr_cellarray{count} = GlxCr;
GlxIU_cellarray{count} = GlxIU;
GlxFitError_cellarray{count} = GlxFitError;
GlxIU_cellarray {count} = GlxIU;
GlxFitError_cellarray{count} = GlxFitError;
Glx_CSFCorr_cellarray{count} = GlxIU_CSFcorr;
Glx_TissCorr_cellarray{count} = Glx_TissCorr;
Glx_AlphaTissCorr{count} = Glx_AlphaTissCorr;
Glx_AlphaTissCorr_GrpNorm_cellarray{count} = Glx_AlphaTissCorr_GrpNorm;
display ('tissue conc');
%Loading Tissue Conc variables/data into arrays
GMFra_cellarray{count} = GMFra;
WMFra_cellarray{count} = WMFra;
CSFfra_cellarray{count} = CSFfra;
count = count + 1;
end
end
%array of headers, values-- MAKE SURE THESE ARE IN THE SAME ORDER
%put these 2 into an outputcell and write to excel
display ('Getting ready to output')
output_header_cellarray = ... %Headers for output document
[{'PID'},{'GABAConcCr'}, {'GABAConcIU'}, {'GABAFitError'}, {'GABA_CSFCorr'}, {'GABA_TissCorr'}, {'GABA_AlphaTissCorr'} , {'GABA_AlphaTissCorr_GrpNorm'} , {'GlxConcCr'} , {'GlxConcIU'} , {'GlxFitError'} , {'Glx_CSFCorr'} , {'Glx_TissCorr'} , {'Glx_AlphaTissCorr'} , {'Glx_AlphaTissCorr_GrpNorm'} ];
output_value_cellarray = ...%Data that goes into each column
[MAT_filename_cellarray,GABACr_cellarray, GABAIU_cellarray, GABAFitError_cellarray, GABA_CSFCorr_cellarray, GABA_TissCorr_cellarray, GABA_AlphaTissCorr_cellarray, GABA_AlphaTissCorr_GrpNorm_cellarray , GlxCr_cellarray , GlxIU_cellarray , GlxFitError_cellarray, Glx_CSFCorr_cellarray , Glx_TissCorr_cellarray , Glx_AlphaTissCorr_cellarray , Glx_AlphaTissCorr_GrpNorm_cellarray];
output_cell = [output_header_cellarray; output_value_cellarray]; %write header + value cellarrays
output_xls_filename = 'Gannet_Quantify_Extract';
xlswrite(output_xls_filename, output_cell);
  6 Comments
Walter Roberson
Walter Roberson on 30 Jul 2018
Glx_AlphaTissCorr{count} = Glx_AlphaTissCorr
Notice that you are assigning to the same variable as you are reading from and you are asking to store the entire variable to a part of the variable. That typically only makes sense in certain linked list type procedures.

Sign in to comment.

Accepted Answer

Guillaume
Guillaume on 30 Jul 2018
Error on
Glx_AlphaTissCorr{count} = Glx_AlphaTissCorr
Well, the error is clear, Glx_AlphaTissCorr is not a cell array.
Even if it were, the line makes no sense as it tries to assign a variable as a member of itself. Considering that all your cell arrays are named xxx_cellarray, the left hand side is suspicious. And considering that on the previous line, you've already assigned Glx_AlphaTissCorr to its corresponding cell array, I suspect that the fix is to simply remove the offending line.
  1 Comment
Holly Pothier
Holly Pothier on 30 Jul 2018
Thank you for pointing that out. I don't know why I didn't notice that simple mistake.

Sign in to comment.

More Answers (0)

Categories

Find more on Structures in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!