How to solve: Error using "csvread". Too many output arguments
이전 댓글 표시
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
madhan ravi
2019년 1월 30일
[num,txt,raw{k}] = xlsread(myfilename);
% ^^^------- use xlsread to read the file with three outputs because csread supports only one
Gagan Bansal
2019년 1월 30일
madhan ravi
2019년 1월 30일
try readtable()
Gagan Bansal
2019년 1월 30일
Gagan Bansal
2019년 1월 30일
madhan ravi
2019년 1월 30일
Why do you need three outputs? you seem to be using only the numeric datas right?
Gagan Bansal
2019년 1월 30일
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
2019년 1월 30일
1 개 추천
If you have both text and numeric data, I suggest you try READTABLE instead.
M
2019년 1월 30일
0 개 추천
As the error says, you are requesting two many outputs arguments.
The function 'csvread' only returns one output.
카테고리
도움말 센터 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!