Storing a 1x500-double that's imbedded in a loop
조회 수: 5 (최근 30일)
이전 댓글 표시
Hello all,
My question lies in how to output or store each value of "v" that is inside my for loop.
I know I can leave it unsupressed and it will pop out 10 different 1x500 doubles in the command window, but what I really want is for the loop to output "v" everytime it iterates, essentially giving me something like v1, v2, v3... v10 so I can look at each 1x500 double individually.
If anyone can offer any help, guidance, or advice I would truly appreciate it. This doesn't seem like something too hard to do but I am quite the noob when it comes to using MATLAB, so I apologize in advance if this is something blatanly obvious that I just don't know how to do.
clc
clear all
t = linspace(0,30,500);
g = 9.81;
m = [0.0008877 0.0017754 0.0026631 0.0035508 0.0044385 0.0053262...
0.0062139 0.0071016 0.0079893 0.008877];
rho = 1.225;
A = 0.19113;
Cd = 0.819346574;
k = (1/2).*Cd.*rho.*A;
v = zeros(1,10);
% Vt = zeros();
% Y = zeros();
% x = zeros();
for i=1:10
Vt = sqrt((m(1,i).*g)./k);
Y = (g.*t)./Vt;
v = Vt.*tanh(Y.*(pi/180));
plot(t,v)
hold on
end
댓글 수: 0
채택된 답변
Walter Roberson
2020년 12월 10일
v(i,:) = Vt.*tanh(Y.*(pi/180));
plot(t, v(i,:));
댓글 수: 2
Steven Lord
2020년 12월 10일
Think about trying to fit half a dozen eggs into a single cup of an egg carton. You can't do it unless the cup is MUCH larger than the eggs (quail eggs inside an egg carton designed for ostrich eggs) or you scramble the eggs (and even then you'd likely have a volume issue.) That's the equivalent of A(1) = 1:6;
If you have an egg carton with two rows and six cups in each row, you can easily fit the six eggs into one row of the carton. That's the equivalent of A(1, :) = 1:6; assuming A is something like zeros(2, 6).
A = zeros(2, 6);
A(1, :) = 1:6 % works
A(1) = 7:12 % errors
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!