How to solve: Error using "csvread". Too many output arguments

조회 수: 5 (최근 30일)
Gagan Bansal
Gagan Bansal 2019년 1월 30일
답변: Jeremy Hughes 2019년 1월 30일
I want to read 40 .csv files. In every csv file there are 251 rows and 4 columns. it is showing error:
Error using csvread
Too many output arguments.
Error in readingALLcsvFILES (line 8)
[num,txt,raw{k}] = csvread(myfilename); %reading the execel file
This is my code:
clear all
numfiles = input('Enter no. of files'); %entering no. of files to be calculated
mydata = cell(1, numfiles); %creating a cell array for all the files
for k = 1:numfiles %begin of loop for each file calculation
myfilename = sprintf('DAT0000%d.csv', k-1); %calling the excel file
[num,txt,raw{k}] = csvread(myfilename); %reading the execel file
n{k}=raw{k}(1,1); % Giving weld time in a cell array of 1x1
n{k}=cell2mat(n{k}); % converting n into a matrix value
DCRfile{k} = raw{k}(2:(n{k}+1),:); % creating a cell array for DCR with time, cuurent and voltage value
DCRfile{k}(:,2)=[]; % deleting 2nd column with value '*'
DCRfile{k}=string(DCRfile{k}); % convering DCR cell array to ta string array
DCRfile{k}(:,1)=erase(DCRfile{k}(:,1),'ms'); % erasing units in DCR string array
DCRfile{k}(:,2)=erase(DCRfile{k}(:,2),'kA');
DCRfile{k}(:,3)=erase(DCRfile{k}(:,3),'V');
DCRfile{k}=double(DCRfile{k}); % converting string array to a numeric array
%Calculation of DCR
for i = 1:n{k}
DCR{k}(i) = (DCRfile{k}(i,3))/(DCRfile{k}(i,2))*1000;
end
%Calculation of R(min) and Time at R(min)
[Rmin{k},Tmin{k}] = min(DCR{k});
%Calculation of Beta Peak
Rmax{k} = 0;
for i = Tmin{k}:n{k}
% DCRx(i-Tmin+1)=DCR(i);
if Rmax{k} < DCR{k}(i)
Rmax{k} = DCR{k}(i);
end
end
Beta{k} = Rmax{k};
Tmax{k} = find(DCR{k}==Beta{k}); %Time at Beta Peak
%Mean DCR
DCRmean{k}=sum(DCR{k})/n{k};
%Calculation of Heat Input
for i = 1:n{k}
HI{k}(i) = DCRfile{k}(i,2)*DCRfile{k}(i,2)*DCR{k}(i)/1000;
end
THI{k}=sum(HI{k}); %Total Heat Input
end
  댓글 수: 8
Gagan Bansal
Gagan Bansal 2019년 1월 30일
Yes. my csv file is like:
250
1ms 1kA 10V
2ms 2.2kA 3V
3ms 3.6kA 5.4V
. . .
. . .
. . .
250ms 3.1kA 5.12V
I only need
250
1 1 10
2 2.2 3
3 3.6 5.4
. . .
. . .
. . .
250 3.1 5.12
madhan ravi
madhan ravi 2019년 1월 30일
Well it had already been answered in your previous question so take a moment to read the answers in your previous question!

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

답변 (2개)

Jeremy Hughes
Jeremy Hughes 2019년 1월 30일
If you have both text and numeric data, I suggest you try READTABLE instead.

M
M 2019년 1월 30일
As the error says, you are requesting two many outputs arguments.
The function 'csvread' only returns one output.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by