Write 3x1 matrix to excel file in for loop. How do I write with a for loop in every 3rd cell

2 Ansichten (letzte 30 Tage)
I'm using a for loop to determine the stress state on each layer of a laminate. I need to write each vector in a column of an excel file.
I would like to wirte the first one in B32:B34 and the next in B35:B37 and so on for each layer.
for i=1:NumLayers
LaminaSress = Qs*(Strain+z(i)*Curve);
xlswrite(Filename,LaminaStress,1,'B32')
end

Akzeptierte Antwort

Guillaume
Guillaume am 24 Mär. 2019
One way:
LaminaSress = zeros(3, NumLayers); %assuming that the result of your equation is a 3 elements vector
for layer = 1:NumLayers
LaminaSress(:, layer) = Qs*(Strain+z(layer)*Curve);
end
xlswrite(Filename, LaminaStress, 1, 'B32');
Note that assuming that z is a vector and Qs or Strain and Curve are also vectors , your loop is not even needed. You can get the whole matrix in one go:
LaminaSress = Qs.*(Strain + z .* Curve); %some tranposition may be needed to make sure the vectors are along different dimensions
xlswrite(Filename, LaminaStress, 1, 'B32');
  2 Kommentare
Michael Whipple
Michael Whipple am 24 Mär. 2019
I need the for loop because Qs and the z value change for each layer. I think the first part will work to make it all one matrix and write it all at once.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Export to MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by