How do I fix Invalid first data argument ?

조회 수: 17 (최근 30일)
Daniel Oluwalana
Daniel Oluwalana 2018년 2월 3일
댓글: Walter Roberson 2025년 12월 1일 21:27
Here's my code. Matlab said there's an error using plot. Please help!
plot ('TBC,theta')
hold on
plot ('TAB, theta')
hold off
grid on
table('TAB & TBC versus theta')
xlabel('theta/ radians');
ylabel ('TAB &TBC /lb');

채택된 답변

Les Beckham
Les Beckham 2018년 2월 3일
The plot() function requires variables as arguments, not a character vector (which is what you have created by putting single quotes around the arguments). Assuming that TBC, TAB, and theta are existing variables in your workspace with consistent dimensions, the plot() commands should work if you take off the single quotes. Also, I think you might mean title() instead of table() on line 6.

추가 답변 (1개)

JOb
JOb 2025년 12월 1일 20:56
편집: Walter Roberson 2025년 12월 1일 21:17
I have the same question but different:
%% 5. Plot – alle rondes
figure;
plot('laps,lap_times_in_sec'; '-0' 'LineWidth'; 1.5;)
xlabel("Lap number");
ylabel("Lap time (s)");
title("Lap times vs. laps – All tires, All cars");
grid on;
When I run this script I get the following error:
File: Script_Portfolio_blok1.m Line: 47 Column: 28
Invalid expression. When calling a function or indexing a variable, use
parentheses. Otherwise, check for mismatched delimiters.
  댓글 수: 1
Walter Roberson
Walter Roberson 2025년 12월 1일 21:27
plot() expects one of the following as a first parameter:
  • a Y value of type single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | categorical | datetime | duration
  • an X value of type single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | categorical | datetime | duration
  • (seldom, but permitted) a name/value pair
'laps,lap_times_in_sec' is not any of the permitted types, and is also not a valid name for name/value pairs.
Furthermore, parameters to plot() must be separated with commas, not with spaces and not with semi-colons.
The '-0' part looks like an attempt to specify a linespec, However, there is no valid linespec that includes '0' .
I suspect that what you want is
plot(laps, lap_times_in_sec, '-o', 'LineWidth', 1.5)

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

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by