MATLAB Answers

0

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

Asked by Gagan Bansal on 30 Jan 2019
Latest activity Answered by Jeremy Hughes on 30 Jan 2019
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 Comments

Why do you need three outputs? you seem to be using only the numeric datas right?
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
Well it had already been answered in your previous question so take a moment to read the answers in your previous question!

Sign in to comment.

2 Answers

Answer by Jeremy Hughes on 30 Jan 2019

If you have both text and numeric data, I suggest you try READTABLE instead.

  0 Comments

Sign in to comment.


Answer by M
on 30 Jan 2019

As the error says, you are requesting two many outputs arguments.
The function 'csvread' only returns one output.

  1 Comment

Is there any way to use csv file for multiple outputs.

Sign in to comment.