Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
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

Réponse acceptée

Guillaume
Guillaume le 24 Mar 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 commentaires
Michael Whipple
Michael Whipple le 24 Mar 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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Data Distribution Plots dans Help Center et File Exchange

Produits


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by