Error using plot: Not Enough Input Arguments

10 次查看(过去 30 天)
Reading a Table which was converted from a .csv file into a .xslx file. Trying to plot Output Voltage vs. Sensitivity using "plot' function. Returns error labeled "Error using plot ; Not Enough Input Arguments. " Error is in Line 14. Tried using the readcsv command with the original .csv file and still recieve the same error in the line for the plot function. I will attach my code and the .xlsx file. Any help would be much appriecitated.
CODE:
% Experiment 4
% Computations and Generated Plots
% Group 4-08; Members: Charlie Johnson, Peter Bohlen
clear variables
clc
close all
% Load the xlsx file of saved data from lab 3.1
data1 = readtable('force_transducer_output_4-08.xlsx');
%data1.Properties.VariableNames
x1 = data1.('XTrace1CH1');
y1 = data1.('YTrace1CH1');
% Generate a plot - this is the force transducer plot
figure (1)
plot(x1, y1);
grid on
hold on
title('Force Transducer Output Voltage and Sensitivity');
xlabel('Output Voltage mV');
ylabel('Sensitivity mV/lb');
hold off
  1 个评论
Peter Bohlen
Peter Bohlen 2023-11-14
Error using plot
Not enough input arguments.
Error in ForceTransducer (line 14)
plot(x1, y1);

请先登录,再进行评论。

采纳的回答

Chunru
Chunru 2023-11-14
Your data is not in right format. Here is one way to convert the string to number.
% Experiment 4
% Computations and Generated Plots
% Group 4-08; Members: Charlie Johnson, Peter Bohlen
% Load the xlsx file of saved data from lab 3.1
data1 = readtable("https://www.mathworks.com/matlabcentral/answers/uploaded_files/1538602/force_transducer_output_4-08.xlsx");
%data1.Properties.VariableNames
x1 = data1.('XTrace1CH1');
y1 = data1.('YTrace1CH1');
whos
Name Size Bytes Class Attributes cmdout 1x33 66 char data1 32001x2 9217511 table x1 32001x1 4608144 cell y1 32001x1 4608144 cell
x1=str2num(cell2mat(x1));
y1=str2num(cell2mat(y1));
% Generate a plot - this is the force transducer plot
figure (1)
plot(x1, y1);
grid on
hold on
title('Force Transducer Output Voltage and Sensitivity');
xlabel('Output Voltage mV');
ylabel('Sensitivity mV/lb');
hold off
  2 个评论
Peter Bohlen
Peter Bohlen 2023-11-14
编辑:Peter Bohlen 2023-11-14
Thank you so much! That seem to do the trick. My understanding is that the str2num converts text to numerical values, could this be replaced by using readmatrix rather than readtable ?
Also, I have two similar codes that are setup very similar to first. Reading a Table using a .xlsx and using the str2num function. However, both of these codes return the an error not present from the first code: "Error using cat;Dimensions of arrays being concatenated are not consistent. ; Error in cell2mat (line 83); m{n} = cat(1,c{:,n}) ; Error in HandCal (line 13) ; y3 = str2num(cell2mat(y3)); ... It is the same setup as the first line of code, so I'm not sure why it is returning this error. Thank you very much for your help!
% Experiment 4
% Computations and Generated Plots
% Group 4-08; Members: Charlie Johnson, Peter Bohlen
clear variables
clc
close all
% Load the xlsx file of saved data from lab 3.2
data2 = readtable('accelerometer4-08.xlsx');
%data2.Properties.VariableNames
x2 = data2.('XTrace1CH1');
y2 = data2.('YTrace1CH1');
x2 = str2num(cell2mat(x2));
y2 = str2num(cell2mat(y2));
% Generate a plot - this is the transducer of force plot
figure (1)
plot(x2, y2);
grid on
hold on
title('Accelerometer Output Voltage and Sensitivity');
xlabel('Output Voltage mV');
ylabel('Sensitivity mV/g');
hold off
Chunru
Chunru 2023-11-14
Your original xlsx data is not formated as number (instead they are strings) . If you format your xlsx data as number instead of string, you can directry import the data without conversion.
t = readtable("https://www.mathworks.com/matlabcentral/answers/uploaded_files/1538637/accelerometer4-08.xlsx")
t = 32001×2 table
XTrace1CH1 YTrace1CH1 ________________________ ________________________ {'0.000000000000000E+0'} {'2.552538997422763E-3'} {'1.684400000000000E-4'} {'2.288312971646311E-3'} {'3.368800000000000E-4'} {'2.684652010310989E-3'} {'5.053200000000001E-4'} {'2.420425984534537E-3'} {'6.737600000000000E-4'} {'2.684652010310989E-3'} {'8.422000000000000E-4'} {'2.948878036087441E-3'} {'1.010640000000000E-3'} {'2.816765023199215E-3'} {'1.179080000000000E-3'} {'2.948878036087441E-3'} {'1.347520000000000E-3'} {'2.420425984534537E-3'} {'1.515960000000000E-3'} {'2.156199958758085E-3'} {'1.684400000000000E-3'} {'2.816765023199215E-3'} {'1.852840000000000E-3'} {'3.477330087640344E-3'} {'2.021280000000000E-3'} {'2.684652010310989E-3'} {'2.189720000000000E-3'} {'2.816765023199215E-3'} {'2.358160000000000E-3'} {'2.552538997422763E-3'} {'2.526600000000000E-3'} {'2.552538997422763E-3'}

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by