How can I fix the error message in my matlab plotting program?

  • Context: MATLAB 
  • Thread starter Thread starter mooncather
  • Start date Start date
  • Tags Tags
    Matlab Plotting
Click For Summary
SUMMARY

The discussion centers on resolving an error in a MATLAB plotting program, specifically the message "Invalid first data argument." The user attempts to plot a trajectory using the command plot('b-'), which is incorrect as it lacks the necessary data inputs. The correct usage of the plot function requires at least two arguments: the x and y data points to be plotted. The user is advised to replace plot('b-') with a proper data set to visualize the object's path.

PREREQUISITES
  • Basic understanding of MATLAB syntax and functions
  • Familiarity with plotting functions in MATLAB
  • Knowledge of 2D coordinate systems for plotting
  • Understanding of trajectory calculations in physics
NEXT STEPS
  • Review MATLAB's plot function documentation for proper usage
  • Learn about data visualization techniques in MATLAB
  • Explore trajectory calculations and their implementation in MATLAB
  • Investigate error handling in MATLAB programming
USEFUL FOR

Students learning MATLAB, educators teaching programming concepts, and anyone interested in physics simulations and data visualization in MATLAB.

mooncather
Messages
1
Reaction score
0
Okay so I am really new to matlab, I mean REALLY new. I am trying to write a program for one of my classes but I am having some trouble. I keep getting this error message:

? Error using ==> plot
Invalid first data argument

Error in ==> guessTraj at 89
plot('b-')


And here is my code:



Code:
function [output]= guessTraj(target_dis)

target_dis=input('distance :');

error = sqrt(target_dis);

real = isreal(error);

if real == 0 & isnumeric(target)== 0

output = 4

disp('Invalid Distance')

end



angle = input('Please enter the angle in degrees:');

radians = angle * (3.14159/180);

velocity = input('Please enter the velocity the ball is thrown:');

vel_error = sqrt(velocity);

vel_check = isreal(vel_error);



if vel_check == 0

disp('Invalid Velocity')

end



VY = velocity * sin(radians) ;

VX = velocity * cos(radians) ;

t = (2*velocity)/9.81 ;

x_dis = VX * t ;

y_dis = VY * t ;



H1 = target_dis + 2.5 ;

H2 = target_dis - 2.5 ;



x = 0:x_dis/50:x_dis;

plot(x,x_dis,target_dis,0,'mo')

xlabel ('Distance the ball Traveled')

ylabel ('Height of the ball')

legend ('Trajectory of Ball', 'Location', 'SouthEastOutside')

hold on



timeVector = 0:t/50:t;

plot('b-')

if x_dis <= H1 && x_dis >= H2

title('The ball hit the target')

output = 1;

disp('1. The ball hit the target!')



elseif x_dis < H1

title('The ball was underthrown')

under = target_dis-x_dis;

output = 2;

disp('2. The ball was underthrown')



elseif x_dis > H2

title('The ball was overthrown')

over = x_dis-target_dis;

output = 3;

disp('3. The ball was overthrown')

end

I'm not sure what I'm doing wrong. I want to plot the path of the object... What am I doing wrong?

Thanks so much!
Code:
 
Physics news on Phys.org
plot('b-') is not a correct use of plot. It just tells MATLAB to plot using a blue line but doesn't tell it what it should plot. What exactly do you want to do with plot('b-') ?
 
>> help plot
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 12 ·
Replies
12
Views
3K