Hello everybody,
I have a problem concerning the import of spreadsheets.
My goal is, to read/load multiple xlsx Files at once. Those files do all look the same, except for the length of the vectors. Some files are four or five data points longer some are shorter. I use this code:
[Filename, Path] = uigetfile({'*.xlsx','DEWE Files(*.xlsx)'}, 'MultiSelect', 'on','C:\.....'); for k = 1:numel(Filename) File = fullfile(Path, Filename{k}); [~, ~, raw] = xlsread(File); raw(cellfun(@(x) ~isempty(x) && isnumeric(x) && isnan(x),raw)) = {''}; %%Replace non-numeric cells with NaN
R = cellfun(@(x) ~isnumeric(x) && ~islogical(x),raw); % Find non-numeric cells
raw(R) = {NaN}; % Replace non-numeric cells
%%Create output variable
data = reshape([raw{:}],size(raw)); %%Allocate imported array to column variable names
Angle_1{k} = data(:,1); Distance_1{k} = data(:,2); Angle_2{k} = data(:,3); Distance_2{k} = data(:,4); Angle_1_=cell2mat(Angle_1); %cell->double
Distance_1_=cell2mat(Distance_1); %cell->double
Angle_2_=cell2mat(Angle_2); %cell->double
Distance_2_=cell2mat(Distance_2); %cell->double
... end
Sometimes I read/load files which are accidentally the same size/length. For example:
I load two files with the same length:
Angle_1 -> 1×2 cell with 282×1 double 282×1 double
Angle_1_ -> 282×2 double
For those cases I do not face any issues. But when there are some files which differ in size cell2mat does not work. I think I have to fill up all the shorter files with NaN. But for now, I don’t know how to do this.
I would really appreciate any help!
Cheers
Christian
Best Answer