Storing For Loop Data For Future Use In A 3D Plot
이전 댓글 표시
I wish to store three sets of data (X, Y, Z) acquired through a For loop in an array, but I am unsure of how to do so.
The end goal is to place all data onto a 3-D plot, which I assume I would be able to do once the data is in an array.
I am extremely new to matlab, so any assistance is greatly appreciated!
My current work is below:
data = xlsread('VelocityData.xlsx');
[rowsize, colsize] =size(data);
i=1;
j=10;
k=0;
for ii=2:rowsize
A=data(ii,1);
B=data(ii,2);
C=data(ii,3);
X=(((A)-((i)/3)));
Y=(((B)+6)/(j));
Z=(((C)-(2*(k))/(3)));
ii=ii+1;
i=i+1;
j=j+10;
k=(k-5);
end
채택된 답변
추가 답변 (1개)
dpb
2021년 12월 7일
What you're written seems like awfully peculiar manipulations to perform on the variables, but
V=[1:rowsize].'; % temporary vector to build addends
X=data(:,1)-V/3; % subtract i/3 from each row i
Y=(data(:,2)+6)./(10*[1:rowsize].'); % and by tens for column 2
X=(data(:,3)+2*5(V-1)/3; % and by -5 for column 3 (NB: - a - --> a +)
using MATLAB vector indexing addressing, the underlying reason there is a MATLAB! :)
plot3D should then work directly.
Experiment with the expression using V to see how they reproduce your explicit calculations. Such "tricks" are the key to using MATLAB effectively -- one trades memory for operations and the vectorized code operates very quickly once it is into the core MATLAB compiled code called/executed by the intrinsic math operators, etc.
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!