- Matrix - https://www.mathworks.com/help/matlab/math/creating-and-concatenating-matrices.html
- Contour plots - https://www.mathworks.com/help/matlab/ref/contour3.html
Add vectors into a matrix using for loop
조회 수: 6 (최근 30일)
이전 댓글 표시
mode 1 is an imported matrix of 3x7 (imported data)
syms x y z
for x = -0.1:0.05:0.1
for y = x = -0.1:0.05:0.1
for k = 1:3
eps2 = mode1(k,5)*mode1(k,5);
X_0 = [mode1(k,1) mode1(k,2) mode1(k,6)];
X = [x y z];
R = X - X_0;
end
end
end
Want to produce a matrix that stores each vector R. For example the first vector that is produced as row 1, second vector produced row 2, third vector produced row 3, etc. Ultimately I need to contour this.
댓글 수: 0
답변 (1개)
ag
2025년 4월 22일
Hi Steven,
To effectively store each vector "R" as a row in a matrix, you can pre-allocate a zero matrix and then update each row with the vector "R" as you compute them. Below is a code snippet that demonstrates how to accomplish this:
R_matrix = zeros(numRows, numColumns)
rowNum = 0;
% Rest of the code
% Loop start
rowNum = rowNum + 1;
R_matrix(rowNum, :) = R;
% Loop end
You can then use the MATLAB function "contour3", to plot the contour graph.
For more information, please refer to the following MathWorks documentation:
Hope this helps!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!