Using a .csv file, I am attempting to read a set of rows from a .csv file and then write each row to a matrix.
An error occurs that states:
'Index exceeds matrix dimensions.'
Error in Id_Vg (line 17)
meas(j,:) = csvread(filename,0,0,[row 2 row+j 5]);
Is the issue that this line is attempting to write columns 2 to 10 into one element of 'meas'?
I thought that preallocating 'meas' with zeros would allow each individual .csv column and row to be written to 'meas'.
function [ output_args ] = Id_Vg(filename, row,...
nopoints, noskip);
%directory= address of the .csv files "C:\....."
%filename = .csv name "1us.csv"
%row = starting row to ignore all text before values, "120"
%nopoints = number of measurement points at each condition "[1e1 1e3 1e1 1e3 1e2]"
%noskip = determines whether to skip condition "[0 1 0 1 0]" 0=skip.
rowstop = row+sum(nopoints);
M = csvread(filename,row,1,[row 2 rowstop 5]);
meas = zeros(sum(nopoints),4);
for i = 1:length(nopoints)
if noskip(i) == 0
for j=1:sum(nopoints)
meas(j,:) = csvread(filename,0,0,[row 2 row+j 5]);
end
end
end
Edit: Changed 'meas(j)' to 'meas(j,:)' and altered the useful .csv columns so that no empty columns are written to 'meas'.
Error still occurs:
Subscripted assignment dimension mismatch.
I understand this is usually due to, in this case, writing too many .csv columns to a matrix that does not have sufficient columns. This should not be the case as even writing a higher number of zeros to meas produces the same error.
meas(j,:) = ...
. – obchardon