Error using xlsread (line 132) File name must be a character vector. Error in Lab1 (line 8) trial_data1= xlsread(Raw_Data(i),1);
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Muhimbo Karangizi
am 20 Jan. 2019
Kommentiert: Stephan
am 21 Jan. 2019
I've been writing the code to plot the data for a Lab and I'm using a data structure method but I keep getting an error (in my four loop where I use xlsread to read all the files). The error says that I need Raw_Data(which contains an array of all the files I'm calling) as a character vector, in order for xlsread to work. I'm not sure how to do this and I have tried using Char and other methods but it still won't work. Attached is the code. 'CH0' and 'Ch1' are columns in my excel sheet that contain the data I need.
Raw_Data = {'Hot Water Trial 1.xlsx','Hot Water Trial 2.xlsx','Hot Water Trial 3.xlsx','Room Temp Trial 1.xlsx','Room Temp Trial 2.xlsx','Room Temp Trial 3.xlsx','Ice Water Trial 1.xlsx','Ice Water Trial 2.xlsx','Ice Water Trial 3.xlsx'};
data = struct('CH0',[],'CH1',[]);
for i = 1:length(Raw_Data)
trial_data1= xlsread(Raw_Data(i),1);
data(i).CH0=trial_data1(:,3);
data(i).CH1=trial_data1(:,4);
data(i).CH0_mean=mean(data(i).CH0);
data(i).CH1_mean=mean(data(i).CH1);
end
0 Kommentare
Akzeptierte Antwort
Stephan
am 21 Jan. 2019
Hi,
since Raw_data is a cell array use {i} to get the content at i in your for loop:
trial_data1= xlsread(Raw_Data{i},1);
instead of:
trial_data1= xlsread(Raw_Data(i),1);
You can see the difference here:
>> a = Raw_Data{1}
a =
'Hot Water Trial 1.xlsx'
>> whos a
Name Size Bytes Class Attributes
a 1x22 44 char
>> b = Raw_Data(1)
is different to:
b =
1×1 cell array
{'Hot Water Trial 1.xlsx'}
>> whos b
Name Size Bytes Class Attributes
b 1x1 156 cell
Best regards
Stephan
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Variables finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!