I have a problem with plotting two vectors, I want to vary 'z' by a certain amount and 'x' by another amount and plot versus each other, how can i make the matrix dimensions match?
조회 수: 3 (최근 30일)
이전 댓글 표시
x = 2:1:25;
y = x^2;
z = 1:1:28;
plot(z,x)
채택된 답변
추가 답변 (2개)
the cyclist
2018년 11월 24일
Well, it's really up to you to decide. You have a 24-element vector, and a 28-element vector.
Which of those elements align with each other? The first 24 elements of both? Then you could just drop the last 4 elements of z.
Or maybe the two endpoints align, and you need to linearly interpret both vectors onto the same number of points?
It's really not clear from your question. I think you need to think more carefully about what makes sense.
댓글 수: 2
the cyclist
2018년 11월 24일
편집: the cyclist
2018년 11월 24일
Yes, there are an infinite number of ways to make these two vectors the same length. Here are three:
Method 1:
x = [x zeros(1,4)]; % Append 4 zeros to the end of x.
Method 2:
z = z(1:24); % Use only the first 24 elements of z.
Method 3:
x = [x nan(1,4004)]; % Append 4004 NaNs to the end of x.
z = [z nan(1,4000)]; % Append 4000 NaN to the end of z.
(The last one is almost certainly not useful, but who knows?)
My point is that the best method will depend on the relationship between the current elements of x and z. How do they "line up" with each other? That relationship is impossible to understand without more detailed information.
Ikenna Okoye
2018년 11월 24일
댓글 수: 3
the cyclist
2018년 11월 27일
So, you are talking about a pretty major change in your code. You want to take something that was written as a function of one variable, and change it to now be a function two (or maybe three?) variables.
madhan ravi's idea that you will need to use meshgrid is likely part of the solution. Given input of two vectors, that function will create a 2-d grid of all possible combinations of the elements of them.
Then you would use the output of that to build the functions of those two variables. You will probably need to rewrite a lot of lines of code.
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with Aerospace Blockset에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!