Readmatrix is changing the "size" of the data I am trying to retrieve from an Excel file?

3 views (last 30 days)
Sort of a beginner in MatLab here.
I have a very large Excel file that I am trying to read, but I'm only concerned with two columns right now. Both columns have the exact same row range, and I should end up with a nice 6000x1 matrix. However, my second matrix (B1f) is not coming out with this size.
Please note that I'm trying to use the fillmissing command to replace all blank cells with a zero (there are a LOT of empty cells) to aid in not dealing with NaN and whatnot.
Here's the code I've got so far:
[file,filepath] = uigetfile ('*.xlsx');
file = fullfile(filepath,file);
noise = readmatrix(file,'Sheet','continuous-waveforms','Range','B2:B6001');
minValue = min(noise(:));
truezero = noise - minValue;
B1peak = readmatrix(file,'Sheet','continuous-waveforms','Range','CY2:CY6001');
B1f = fillmissing(B1peak,'constant',0);
B1ffix = B1f - truezero; %This is where the different sized matrices occur.
B1pos = B1ffix(B1ffix > 0);
MeanB1 = mean(B1pos);
I don't get any error code, just that "Matrix dimensions must agree", which, duh. My variables in the workspace window confirms the significant difference in matrix sizes.
I've been fighting with this for a while. The same thing was happening with xlsread but I tried switching to readmatrix because it seemed like a little bit better for this.
  3 Comments
Madeline Stalder
Madeline Stalder on 27 May 2021
Edited: Madeline Stalder on 27 May 2021
Yes, B1peak is coming out smaller than it should (5447x1). Also, the size doesn't change after my fillmissing() goes through.
I am using R2020a on Windows 10 and Excel is installed. I can attach the Excel file I'm trying to read right now to see if yours still is good on your end.
I'm wondering if I should instead try to just get matlab to pre-fill in my zeros for me? Or maybe I should just try to download the newest version of MatLab.
Walter Roberson
Walter Roberson on 27 May 2021
You said "a very large" file; if it is more than 5 megabytes you might need to put it into Google Drive or DropBox and post the link.
I do not have Excel installed in Windows, but I could test anyhow.

Sign in to comment.

Answers (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 27 May 2021
Hi,
This is where you have logical indexing that is removing all data points which are less than 0.
B1pos = B1ffix(B1ffix > 0);
MeanB1 = mean(B1pos);

Community Treasure Hunt

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

Start Hunting!