Closed nafraw closed 3 years ago
Hi @nafraw,
I'd be happy to look into this a bit more. Would you be able to provide me with a bit more detail, potentially including a MWE and the MATLAB version you are using? I ask because the line number of stabilizationExample.m
you reference (105) doesn't appear to be consistent with the current version of this script in the repository (where the first call of getStabilizatonMatrices
occurs on line 178).
Best, Alan
Hi @alandegenhart ,
The MATLAB version is R2019a, specifically, '9.6.0.1335978 (R2019a) Update 8'
I am not sure what do you meant by MEW, but the line is indeed line 178. It became line 105 because I was running with a live script, which makes the difference of line count.
Here is the error message without using the live script:
Error using Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To perform elementwise multiplication, use '.'.
Error in getStabilizatonMatrices (line 22) o = -beta*fa.d;
Error in stabilizationExample (line 178) [baselineBeta, baselineO] = getStabilizatonMatrices(baselineStabilizer);
Thank you
Got it -- thanks for the clarification re: the line number. "MWE" == "minimum working example" -- I just wanted to confirm that there weren't any other changes to the script that might be leading to the error. We'll look into it and get back to you soon.
Alan
Hi @nafraw,
Can you confirm if you made any other changes to the code or script on your side? Also, does the error happen every time you run the script or does it seem to be stochastic?
I just downloaded the version on the repo and everything ran for me, so this may be a bit tricky to track down, but we should be able to get to the bottom of it.
Best, Will
Hi @wbishopJanelia ,
I downloaded again the ZIP file and run it again after restarting MATLAB. The error is the same. I ran several times the scripts before, so I don't feel it is stochastic.
When I trace back to line 122, where baselineStabilizer first appeared. The dimension of the field d is already "1x2017 double". 2017 is the number of samples I assume, also verified by: sum(cellfun(@(x) size(x, 2), calibrationData));
If it should not be 2017. as I guess here should be the number of electrode, maybe the bug or difference happens in fitFA.m at line 94: d = nanmean(x)'; that is averaging in a wrong dimension? There I have the returned d being 1x2017, which I believe 83 is a more reasonable number from the comments in the file.
Thanks, PK
Thanks for your reply - this is very helpful. You are correct 2017 is the number of samples. 83 is the number of electrodes, and d should be of size 83*1.
If you put a break at line 94, can you confirm that the size of x is 2017 83 and the size of d is 12017 (from the above it sounds like this indeed the size you are seeing for d). If the size of x is correct but the calculated d is not, then that would point to problem with nanmean. If that is the case, my best guess would be that perhaps you have a non-native version of nanmean floating around somewhere on your MATLAB path that calculates in a direction that is different than the native version.
I would also suggest running the script after resetting the MATLAB search path to the default to make sure there aren't any external dependencies that could be causing unintentional issues.
Ok - doing a bit more sleuthing and I realized that nanmean is not included in the base version of MATLAB but in the statistics toolbox - I didn't realize this when implementing the code. @nafraw if you can confirm that the issue you are seeing comes down to nanmean - and you are using a version not in the stats toolbox, I'll update the repo to include a version of nanmean that will calculate in the right direction and does not require the stats toolbox
The issue should be nanmean. I took over a computer from someone else and the used nanmean certainly does not come from stat toolbox; the previous owner overwritten the default paths with other libraries. I tried again with my own laptop with clean default paths. Now, there is no error and a figure is generated. The called nanmean is now: $MATLAB_path/toolbox/stats/stats/nanmean.m
Thanks for the help!
Sounds great! We're happy to help - feel free to reach out if there are any other issues.
Dear @alandegenhart and @wbishopJanelia
First of all, thank you for the nice article addressing the targeted issue. I am interested in the method. However, I immediately encountered an error while running stabilizationExample.m. There is a dimension mismatch when doing -beta*fa.d, where size(beta) = [10, 83] and size(fa.d) = [1, 2017]. I guess the reason is that you modified core functions after uploading the script. Would you be able to have a look at it?
The error occurs at line 105: [baselineBeta, baselineO] = getStabilizatonMatrices(baselineStabilizer); The error message is shown below:
Error using Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To perform elementwise multiplication, use '.'.
Error in getStabilizatonMatrices (line 22) o = -beta*fa.d;
Thank you