mardi 18 avril 2017

Plotting a streamline plot, quiver plot, or both based on user input. Error message in function

I am attempting to plot a streamline plot, quiver plot, or both based on user input passed through a function I have created. It plots a streamline but when i try to plot a quiver by inputting 'vectors' into my function i get the error code: Matrix dimensions must agree. Error in part3 (line 8)

This error message is also shown in my pictures linked.

My code is linked below as pictures but here is my function and script code text.

Here is my function and script image links: function script

function [ output_args ] = part3(type,x,y,num,startx)

[XX YY]=meshgrid(x,y);
starty=linspace(-1,1,num);
startx1=-startx;
fx=XX;
fy=sin(XX);
if type=='streamlines'
    hold on
    streamline(XX,YY,fx,fy,startx,starty)
    streamline(XX,YY,fx,fy,startx1,starty)
elseif type=='vectors'
    quiver(XX,YY,fx,fy)
elseif type=='both'
    subplot(1,2,1)
    streamline(XX,YY,fx,fy,startx,starty)
    subplot(1,2,2)
    quiver(XX,YY,fx,fy)
end


end

Here is my script:

x=linspace(-2*pi,2*pi,10);
y=linspace(-1,1,30);
startx=ones(size(y));
strmln=30;
part3('vectors',x,y,strmln,startx )

Aucun commentaire:

Enregistrer un commentaire