Strange character output in command line in lieu of numeric array values

4 views (last 30 days)
I am running into a problem where numeric values loaded into an array from an Excel spreadsheet are showing up as strange characters (e.g., empty squares) in the MATLAB command line output. When I run class() on an element of the array, it displays as char, similar to other values input directly in the code using single quotes (e.g., {'11137'}). The values from both sources look similar in the data structures, but the value from the coded array has single quotes around it, whereas the value from the imported array has no quotes around it. I’ve tried to put single quotes around the numeric elements of the imported array (e.g., the quadruple quotes with square brackets below, which was suggested as a work-around in another thread), but I can’t seem to figure out how to get both the quotes and the values (as opposed to the variable name) into the array. My code is below:
% create empty arrays
subject_list_presence={};
subject_list_timing={};
% populate arrays with numeric values from column of spreadsheet
[ndata1, text1, alldata1] = xlsread('/Volumes/lmorett_YCSC_data/EEG_study/Data/GEEG/EEG/0inputparameters/Subject_data');
DimensionsOfFile1 = size(alldata1);
for s=1:nsubj % Loop through all subjects
for j = 1:DimensionsOfFile1(1);
if isequal(subject_list{s},num2str(alldata1{j,1}));
presence = (alldata1{j,2}); % Create subject lists for presence and timing tasks
if isequal(presence, 'Y'); %If presence data good, add to subject_list_presence arrays
presence_subject = ['''' (alldata1{j,1}) '''']; % note quadruple quotes and square brackets
subject_list_presence = [subject_list_presence ; presence_subject];
end
timing = (alldata1{j,3});
if isequal(timing, 'Y'); %If timing data good, add to subject_list_timing array
timing_subject = ['''' (alldata1{j,1}) ''''];
subject_list_timing = [subject_list_timing ; timing_subject];
end
end
end
% use each value in array to perform some functions
for s=1:nsubjpr % Loop through all subjects with presence data
fprintf('\n\n\n**** %s: Loading data for epoching, presence task ****\n\n\n', subject_list_presence{s});
Does anyone know whether single quotes around the values in the imported array would solve the issue with the strange character command line output? (My goal is for MATLAB to output the value in place of the strange character.) If so, explanations as to how I can include them would be greatly appreciated. If not, alternate suggestions that would achieve my goal would be greatly appreciated.

Answers (1)

Walter Roberson
Walter Roberson on 27 Oct 2017
We as on-lookers have no reason to expect that alldata1{j,1} might not be numeric at the time you construct those character strings.
Note that if you have an original cell that happens to have the form of a number, possibly with leading or trailing spaces, then it will generally be converted to numeric in the raw output of xlsread. This can be a problem at times. The situation is even worse with readtable() from .xlsx files, as that code has no way to prevent the transformation to numeric from happening.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!