Beginner: Z must be a matrix, not a scalar or vector

조회 수: 7 (최근 30일)
A
A 2013년 12월 11일
답변: A 2013년 12월 11일
Hi guys,
I'm trying to plot the below function as a shape. But I'm getting an error. I'm thinking it has to do with matrices, etc. and I'm not sure how to deal with that. Could you please help?
Thanks
>> Nc=4/3;
>> Na=1.336;
>> RT = 0.2;
>> K = 5;
>> R = 337.5/K;
>> V = 12;
>> Ref = 20;
>> SF = 20;
>> ACD = -5:5;
>> AL = -5:5;
>> Alm = AL+RT;
>> I = ((1000*Na*(Na*R-(Nc-1)*Alm)));
>> surf(I);
*Error using surf (line 75)
Z must be a matrix, not a scalar or vector*

답변 (3개)

Walter Roberson
Walter Roberson 2013년 12월 11일
You set ACD to be a vector but you do not use it.
You set AL to be a vector, and you us it in ALm, so ALm is a vector. Then you calculate "I" in terms of Alm and a number of constants, so "I" will be a vector. But you cannot surf() a vector: whatever you surf must be M x N where M and N are both at least 2.
I would speculate you missed an ACD term in calculating "I", and that you will want to use meshgrid() or bsxfun() to calculate "I". You will probably also need to change all of the "*" in your calculation of "I" into ".*"

A
A 2013년 12월 11일
Thanks for your response. ACD is just a constant that I will use later, so you can ignore that.
So I think I get that I'd need to use meshgrid.
But how can I do that? is it as simple as
[i] = meshgrid(I); surf(i);
?
  댓글 수: 1
Walter Roberson
Walter Roberson 2013년 12월 11일
No, you have a problem at the moment in that your calculation only varies in one dimension, AL. Your data would be suitable for a simple plot,
plot(AL, I)
In order to have a surface, you need to have two axes that you are calculating over.

댓글을 달려면 로그인하십시오.


A
A 2013년 12월 11일
Thank you! I have figured it out. It's only my first day of using MatLab. Thanks!

카테고리

Help CenterFile Exchange에서 Pulse and Transition Metrics에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by