MATLAB Answers

Error using xlsread (line 132) File name must be a character vector. Error in Lab1 (line 8) trial_data1= xlsread(Raw_Data(i),1);

36 ビュー (過去 30 日間)
Muhimbo Karangizi
Muhimbo Karangizi 2019 年 1 月 20 日
Commented: Stephan 2019 年 1 月 21 日
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);

  0 件のコメント

サインイン to comment.


Stephan 2019 年 1 月 21 日
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

  2 件のコメント

Muhimbo Karangizi
Muhimbo Karangizi 2019 年 1 月 21 日
Thank you Stephan !
This fixed my problem and will help me in the future with understanding Structs.
Stephan 2019 年 1 月 21 日
if my answer was useful please accept it.

サインイン to comment.

More Answers (0)

サインイン してこの質問に回答します。

Translated by