Can you please say why it is coming this error? i need a solution

조회 수: 2 (최근 30일)
md sazzad
md sazzad 2023년 4월 19일
편집: Walter Roberson 2023년 4월 21일
function [Sample,Status,P0,RawP,RawT]=extract_data_P0(Nomfichier,SW_version)
opts=detectImportOptions('Capteur2125011.txt');
opts.DataLine=7;
opts.VariableNames={'SampleNumber','ReceivedFrame'};
RawData=(readtable(Nomfichier,opts));
Sample=table2array(RawData(:,1));
RawFrame=table2array(RawData(:,2));
for i=1:length(RawFrame)
Status(i,1)=hex2dec(cat(2,RawFrame{i}(7:8),RawFrame{i}(10:11)));
P0(i,1)=hex2dec(cat(2,RawFrame{i}(19:20),RawFrame{i}(22:23)));
%Calcul de la pression
RawP(i,1)=hex2dec(cat(2,RawFrame{i}(25:26),RawFrame{i}(28:29),RawFrame{i}(31:32),RawFrame{i}(34:35)));
if RawP(i,1)>=2^23
RawP(i,1)=-1*(2^24-RawP(i,1));
end
if SW_version == 0
%Calcul de la température (versions SW 1.0.0.a et 1.1.0.a)
Dummy_temp=hex2dec(cat(2,RawFrame{i}(37:38),RawFrame{i}(40:41)));
if Dummy_temp<8192
RawT(i,1)=0.03125*Dummy_temp;
else
RawT(i,1)=-0.03125*(16384-Dummy_temp);
end
else
%Calcul de la température (versions SW >= 1.2.0.a)
Dummy_temp=hex2dec(cat(2,RawFrame{i}(37:38),RawFrame{i}(40:41)));
if Dummy_temp<32768
RawT(i,1)=0.03125*Dummy_temp;
else
RawT(i,1)=-0.03125*(65536-Dummy_temp);
end
end
end
Not enough input arguments.
Error in extract_data_P0 (line 7)
RawData=(readtable(Nomfichier,opts));

답변 (1개)

Walter Roberson
Walter Roberson 2023년 4월 19일
opts=detectImportOptions('Capteur2125011.txt');
There you are asking to analyze a specific file, expecting the file to be in the current directory or somewhere on the MATLAB path.
RawData=(readtable(Nomfichier,opts));
There you ask to readtable(), passing in the content of Nomfichier as the file name to process -- a name that is fairly likely to be different than 'Capteur2125011.txt' .
It is not necessarily an error to analyze one file but read a different file with those options, as you might have created a "template" that you expect other files to be exactly the same for. But it is at the very least suspicious, and runs the risk of error in case the actual input file is different than what is in 'Capteur2125011.txt' -- and the risk that 'Capteur2125011.txt' might not be available.
Anyhow, the error that you are getting is that when you invoked the function, you did not provide a value for the input variable Nomfichier but the code needs you to have provided a file name there.
You probably pressed the green Run button to run the function. When you press the green Run button, the effect is to run the function with no parameters.
Under no circumstances will MATLAB hunt around looking to see if it can find some outside variable named Nomfichier to use the value of for the purpose of this function.
You have a small number of choices:
  • redesign the code to use a constant file name
  • redesign the code so that it detects whether you passed a file name or not, and if you did pass in a file name then use it and otherwise use a constant file name
  • redesign the code so that it specifically tests to see whether you passed in a file name, and if not then gives you more specific error message
  • or... always make sure that you pass in a file name when you run the code, by not pressing the green Run button to run the code, and instead invoke it passing in a file name.
Reminder: passing in fully-qualified file names is better practice than assuming that the given name can be found somewhere on the MATLAB path.

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by