problem with assigning in a loop

my code runs correctly when lc is 1,I want lc>1 ;
Ed is 45*6 matrix and I think there is a way to assign Ed for lc>1 .
What can I do?
please help.
for i=1:lc
ff=f(:,i);
[a,r]=solveq(K,ff,bc);
Ed=extract(Edof,a);
end
----------------------------------------
function [ed]=extract(edof,a)
[nie,n]=size(edof);
t=edof(:,2:n);
for i = 1:nie
ed(i,1:(n-1))=a(t(i,:))';
end

 Accepted Answer

Image Analyst
Image Analyst on 14 Dec 2014
Edited: Image Analyst on 14 Dec 2014
Store the various values of Ed for different iterations in a cell array
Ed{i} =extract(Edof,a);
or a 3D array
thisEd=extract(Edof,a);
allEd(:,:,i) = thisEd;
If you use a 3D array, be sure to preallocate before the loop starts
Ed=allED(45,6,lc);

3 Comments

Thank you my friend,
It's good help but I got this error, how can I fix this?
??? Cell contents assignment to a non-cell array object.
Ed{i} =extract(Edof,a);
Thanks.
Maybe you need to define Ed as a cell before the loop
Ed = cell(1, lc);
excellent, thanks.

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Asked:

on 14 Dec 2014

Commented:

on 14 Dec 2014

Community Treasure Hunt

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

Start Hunting!