Error Z must be a matrix, not a scalar or vector.
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
mohsen
il 5 Mar 2016
Modificato: Walter Roberson
il 5 Mar 2016
prompt = 'what is the value of x';
prompt2 = 'what is value of y';
x = input(prompt);
y = input(prompt2);
u = 10*sin(200*x)+0.1*cos(10*y)+(100*x)/y;
[X,Y] = meshgrid(x,y);
Z = u
figure
mesh(Z)
Also, how would I use the element wise operator in this code?
0 Commenti
Risposta accettata
Star Strider
il 5 Mar 2016
I prefer inputdlg to input, but that’s a personal preference and not a criticism of your code in that regard.
As best I can determine, you have your statements in the wrong order. Also, you need to define ranges for ‘x’ and y, not simply scalar values.
See if something like:
x = 1:10;
y = 20:30;
u = @(x,y) 10*sin(200*x)+0.1*cos(10*y)+(100*x)./y; % Create Anonymous Function From ‘u’
[X,Y] = meshgrid(x,y);
Z = u(X,Y);
figure(1)
mesh(X, Y, Z)
That works for me when I run it. The only changes I made in your code otherwise were to vectorise the division in ‘u’, to create a call to ‘u’ in your ‘Z’ assignment, and to add ‘X’ and ‘Y’ to your mesh call, because those tend to produce better (and more understandable) plots.
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!