1

I want a new answer to be output every iteration of this for loop. Currently it is update the fluence to be just the last last loop output.

for i = 1:nx
    fluence= data1cm(i).data(:,3).*25000000.*(energygap);
    %dim=size(c)
    %'fluence' num2str((i)+1)= fluence;
end
1

1 Answer 1

2

Just as you index into data1cm(i) you can save the value into fluence in the same manner, e.g. if the result of data1cm(i).data(:,3).*25000000.*(energygap) is scalar you can do

for i = 1:nx
    fluence(i)= data1cm(i).data(:,3).*25000000.*(energygap);
end

Then fluence will be a 1*nx array of all the results.

For efficiency one should always initialise the variable, that is create it with some temporary values and then overwrite these values.

fluence = zeros(1,nx);
for i = 1:nx
    fluence(i)= data1cm(i).data(:,3).*25000000.*(energygap);
end

Here I initialise fluence with zeros, and then all of these zeros are overwritten by the result of data1cm(i).data(:,3).*25000000.*(energygap);. Other initialisations are e.g. ones and nan.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.