Info
This question is closed. Reopen it to edit or answer.
How to get round this problem with xlsread/xlwrite
1 view (last 30 days)
Show older comments
Hi all, I have a problem with xlsread altering the values of some variables when I am loading data from a spreadsheet created by the xlwrite function. I suspect it is something to do with the variables themselves but am unsure. I describe the problem below:
I collected some variables from a spreadsheet as follows:
filename=uigetfile('*.*');
[NUM,TXT,RAW] = xlsread(filename);
name=TXT{3,20};
ABF_name=TXT{4,20};
Initial_weight=NUM(8,5);
Tr_day_1_date=TXT{25,1};
Num_tr_days = NUM(5,20);
Reward_pos = TXT{6,20};
FoR = TXT{7,20};
I save these variables into a new spreadsheet; as I am on a Mac I use the xlwrite function to write the data to an xlsx file
xlwrite('Lever_training_metadata.xlsx',metadata);
When running the script again, I want to reload this data and append any new data:
if exist('Lever_training_metadata.xlsx','file')
[A,B,oldmetadata]=xlsread('Lever_training_metadata.xlsx','A1:G1000');
oldmetadata = oldmetadata(any(cellfun(@(x)any(~isnan(x)),oldmetadata),2),:);
else ....
end
These are the values copied directly from the initial .xlsx file:
name ABF_name Initial_weight Tr_day_1_date Num_Tr_days Reward_pos FoW
M1_140927A 000 24.9 14o03 12 F W
However, when I try loading the file using xlsread, I end up with the following in matlab:
oldmetadata =
Columns 1 through 4
'name' 'ABF_name' 'Initial_weight' 'Tr_day_1_date'
'M1_140927A' '000' '24.9' '9'
Columns 5 through 7
'Num_Tr_days' 'Reward_pos' 'FoW'
'12.0' [ 10] '11'
For some reason the values of Tr_day_1_date, Reward_pos and FoW have been altered.
Can anyone see any reason why this would be happening? I hope the jumble above is understandable enough.
Cheers,
Josh
5 Comments
dpb
on 27 Oct 2014
I'd suggest attaching a section of the .xls file that doesn't seem to import successfully so others can 'spearmint with the actual data instead of talking about it.
I don't have Mac so would have to be PC version but if there's something funky about the file itself perhaps it would show up.
As you say, you can always export to CSV altho the Matlab functions specifically for them are able to read only numeric data so you'd have to read them with textscan or the like.
Answers (0)
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!