contour plot getting error

Hello,
I am trying to get two contour plots with my date below, and I'm getting error for the second one, I really appreciate your help to guide me,
clear all
close all
clc
[m,a]=meshgrid(0:1/11:1,0:5000:50000)
v=m.*a
[C,h]=contour(m,a,v);
set(h,'ShowText','on','TextStep',get(h,'LevelStep')*2);
colormap cool
%U=q/M^2
U=[1481.354 1232.613 1018.924 836.3533 681.2936 550.4372 440.7684 349.5441 275.1887 216.6139 170.5264]
KIAS=661*((U)*m.^2/1481).^(1/2)
figure
[A,B]=contour(m,a,KIAS);
set(B,'ShowText','on','TextStep',get(B,'LevelStep')*2);
colormap cool

댓글 수: 2

Walter Roberson
Walter Roberson 2013년 9월 3일
What error are you getting?
Salar
Salar 2013년 9월 3일
Error using contour (line 72) Z must be size 2x2 or greater.
Error in MAE325_HW2 (line 16) contour(m,a,KIAS);

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

 채택된 답변

Walter Roberson
Walter Roberson 2013년 9월 3일

0 개 추천

Your KIAS comes out as 1 x 12. When you have a vector as the third argument of contour() then the vector is treated as the list of contour levels, not as Z.
After that, the contour() error checking gets confused about what exactly is wrong: the real problem it should be diagnosing at that point is that you would have provided only two coordinate matrices (X, Y) instead of one (Z) or three (X, Y, Z).
Remember, U is a row vector, so it is 1 x something, and when you do an algebraic matrix multiplication (1 x something) x matrix, then the result is going to be 1 x some dimension, rather than a rectangle.
You might perhaps be wanting to do some repmat() somewhere along the line. And maybe a transpose or three. I can't tell.

댓글 수: 6

Salar
Salar 2013년 9월 4일
thanks, I tired a couple of times using repmat and transpose, but I can't get this to work, can you please take a give it a try tell me what am I doing wrong? thanks!
Walter Roberson
Walter Roberson 2013년 9월 4일
You need to indicate what mathematical result you want. You have currently have U*m where U is a 1 x 11 row vector and m is a 11 x 12 array. The result is going to be 1 x 12 for KIAS. But to be useful for that contour() call, you need a 11 x 12 KIAS (same size as m). You could repmat(U, 11, 1) so that U become 11 x 11 and so U*m becaome 11 x 12, but would that be what you want mathematically? The result would be the same as if you had repmat(KIAS,11,1) with your current KIAS definition -- which clearly would not give you nice contours.
This is why we need to know mathematically what you expect for each KIES entry.
I changed my code to this : I get a graph but it doesn't look right,
clear all
close all
clc<<<<>>>>
[m,a]=meshgrid(0:1/11:1,0:5000:50000)
v=m.*a
[C,h]=contour(m,a,v);
set(h,'ShowText','on','TextStep',get(h,'LevelStep')*2);
colormap cool
%U=q/M^2
U=[1481.354 1232.613 1018.924 836.3533 681.2936 550.4372 440.7684 349.5441 275.1887 216.6139 170.5264];
%u=repmat(U,11);
KIAS=661*(U*m.^2/1481).^(1/2);
KIAS=[KIAS;KIAS;KIAS;KIAS;KIAS;KIAS;KIAS;KIAS;KIAS;KIAS;KIAS]
figure
[A,B]=contour(m,a,KIAS);
set(B,'ShowText','on','TextStep',get(B,'LevelStep')*2);
colormap cool
Salar
Salar 2013년 9월 4일
편집: Walter Roberson 2013년 9월 4일
I have apicture of the ideal graph which is generated by Excel, it is attached here, I need this graph to be like this,
As I wrote above,
The result would be the same as if you had repmat(KIAS,11,1) with your current KIAS definition -- which clearly would not give you nice contours.
Which is also why I wrote,
This is why we need to know mathematically what you expect for each KIAS entry.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Contour Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by