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

1 回表示 (過去 30 日間)
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

採用された回答

Guillaume
Guillaume 2019 年 3 月 24 日
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 件のコメント
Michael Whipple
Michael Whipple 2019 年 3 月 24 日
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.
Michael Whipple
Michael Whipple 2019 年 3 月 25 日
That worked perfect. Thanks

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by