MATLAB: Error Using a loop: Conversion to double from cell is not possible.

cell arraysdoublefor loopMATLABseeking vulnerabilityvariable

Hello everyone,
On executing following code:
for w = 1:10
PN = PName{w};
CS = CSize{w};
Project = [PN CS];
Project = sortrows(Project,1);
Project = Project(11:end,1:end);
Proj(w) = Project;
end
I am getting error: Conversion to double from cell is not possible..
Code is running well till Project = Project(11:end,1:end);
Size of Project is: 4227×2 cell.
Error is while assigning a values to a new variable using a loop at Proj(w) = Project;
Any help would be appreciated 🙂
Regard,s
Waqar Ali

Best Answer

Perhaps what you need is struct. Try the following:
s = struct();
for w = 1:10
PN = PName{w};
CS = CSize{w};
Project = [PN CS];
Project = sortrows(Project,1);
Project = Project(11:end,1:end);
FieldName = strcat('Proj', num2str(w));
s.(FieldName) = cell2mat(Project);
end
You will get your 10 "variables" within structure s. You can refer them as s.Proj1, s.Proj2, etc.
Please let me know if it works for you.