Asked by Gagan Bansal
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

Answer by Jeremy Hughes
on 30 Jan 2019

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

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.

Gagan Bansal
on 30 Jan 2019

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

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 8 Comments

## madhan ravi (view profile)

Direct link to this comment:https://it.mathworks.com/matlabcentral/answers/442280-how-to-solve-error-using-csvread-too-many-output-arguments#comment_665832

## Gagan Bansal (view profile)

Direct link to this comment:https://it.mathworks.com/matlabcentral/answers/442280-how-to-solve-error-using-csvread-too-many-output-arguments#comment_665867

## madhan ravi (view profile)

Direct link to this comment:https://it.mathworks.com/matlabcentral/answers/442280-how-to-solve-error-using-csvread-too-many-output-arguments#comment_665868

## Gagan Bansal (view profile)

Direct link to this comment:https://it.mathworks.com/matlabcentral/answers/442280-how-to-solve-error-using-csvread-too-many-output-arguments#comment_665876

## Gagan Bansal (view profile)

Direct link to this comment:https://it.mathworks.com/matlabcentral/answers/442280-how-to-solve-error-using-csvread-too-many-output-arguments#comment_665878

## madhan ravi (view profile)

Direct link to this comment:https://it.mathworks.com/matlabcentral/answers/442280-how-to-solve-error-using-csvread-too-many-output-arguments#comment_665879

## Gagan Bansal (view profile)

Direct link to this comment:https://it.mathworks.com/matlabcentral/answers/442280-how-to-solve-error-using-csvread-too-many-output-arguments#comment_665881

## madhan ravi (view profile)

Direct link to this comment:https://it.mathworks.com/matlabcentral/answers/442280-how-to-solve-error-using-csvread-too-many-output-arguments#comment_665882

Sign in to comment.