I encountered an 'invalid use of operator' error message.

I encountered an 'invalid use of operator' error message when excuted this below.
load(fullfile(E:\charite\Data\EGCG_Round3\MRE\MouseAtlasReg\ProcessedShort\20241024_sl_MRE_Day18_Cage1_3505_MRE\mreCubes1,'ventricles.mat'));

 Accepted Answer

Hi,
you need to place single or double quotes around the path. With single quotes:
load(fullfile('E:\charite\Data\EGCG_Round3\MRE\MouseAtlasReg\ProcessedShort\20241024_sl_MRE_Day18_Cage1_3505_MRE\mreCubes1','ventricles.mat'));
If you are just getting started with MATLAB, you may find the MATLAB Onramp helpful.
Best wishes,
Harald

6 Comments

Thanks!!!! It works, I will take the course of MATLAB Onramp later!!
Hi, I’ve run into another issue: 'Arrays have incompatible sizes for this operation' when I execute the code below. Thanks again for your assistance!
load(fullfile('E:\mreCubes1','ventricles.mat'));
load(fullfile('E:\mreCubes1\rois','WholeBrain_115cut.mat'));
WholeBrain_115cut_noVentricle = and(WholeBrain_115cut, ~ventricles);
save(fullfile('E:\mreCubes1','WholeBrain_115cut_noVentricle'),'WholeBrain_115cut_noVentricle')
I assume the line where you call and is where the error occurs. If that's not correct, or if you ask about other errors in the future, please show the full and exact text of the error message (all the text displayed in red in the Command Window, and if there are any warning messages displayed in orange, please show us those too.) The exact text may be useful and/or necessary to determine what's going on and how to avoid the warning and/or error.
If that assumption is correct, please show us the sizes of the two variables you're using as inputs to and. You can do so using the whos function immediately before the line that throws the error. If the variables have more dimensions than whos can show in its output (if one of the variables has 5 or more dimensions, like z in the example below) please show the size of that variable as well.
clear all
x = 1;
y = rand(2);
z = ones(2,3,4,5,6);
whos
Name Size Bytes Class Attributes x 1x1 8 double y 2x2 32 double z 5-D 5760 double
size(z)
ans = 1×5
2 3 4 5 6
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
The and function requires its inputs to be compatibly sized.
and([-1 0 1], [2;3;4;5])
ans = 4x3 logical array
1 0 1 1 0 1 1 0 1 1 0 1
If they're not:
and(ones(2), ones(3)) % What does it mean to and together a 2-by-2 and a 3-by-3?
Error using &
Arrays have incompatible sizes for this operation.
Hi, here is the full and exact text of the error message, now it shows "Dot indexing is not supported for variables of this type." o(╥﹏╥)o
>> GenerateMasksWithoutVentricles
E:\charite\Data\EGCG_Round3\MRE\MouseAtlasReg\ProcessedShort\20241024_170015_20241024_sl_MRE_Day18_Cage1_3505_MRE_1_1\mreCubes1\TransformParameters.0_Par0025affine.txt\rois
Dot indexing is not supported for variables of this type.
Error in GenerateMasksWithoutVentricles (line 53)
WholeBrain_115cut_noVentricle = and(WholeBrain_115cut.mat, ~ventricles.mat);
Here is the full text
pathDefault = 'E:\charite\Data\EGCG_Round3\MRE\MouseAtlasReg\ProcessedShort\20241024_170015_20241024_sl_MRE_Day18_Cage1_3505_MRE_1_1\mreCubes1';
listing = dir(pathDefault);
listing(1:2) = [];
for iFolder = 1 : length(listing)
currentPath = fullfile(listing(iFolder).folder, listing(iFolder).name);
path = fullfile(currentPath,'rois'); %change back to rois
disp(path);
if strcmp(listing(iFolder).name,'results')%doesnt run the loop for this folder
continue;
end
load(fullfile('E:\mreCubes1', 'ventricles.mat'));
ventricles_dilated1pix=imdilate(ventricles,strel('disk', 1));
save(fullfile ('E:\mreCubes1', 'ventricles_dilated1pix'),'ventricles_dilated1pix');
load(fullfile('E:\mreCubes1','ventricles.mat'));
load(fullfile('E:\mreCubes1\rois','WholeBrain_115cut.mat'));
WholeBrain_115cut_noVentricle = and(WholeBrain_115cut.mat, ~ventricles.mat);
save(fullfile ('E:\mreCubes1', 'WholeBrain_115cut_noVentricle'),'WholeBrain_115cut_noVentricle')
Hi,
you should not work with the .mat files in that line, but with the variables that you have imported from them:
If the variables are named the same as the .mat files, this would be
WholeBrain_115cut_noVentricle = and(WholeBrain_115cut, ~ventricles);
like you have shown in an earlier version.
In general, it will be
varC = and(varA, ~varB);
Best wishes,
Harald

Sign in to comment.

More Answers (2)

load(fullfile('E:\charite\Data\EGCG_Round3\MRE\MouseAtlasReg\ProcessedShort\20241024_sl_MRE_Day18_Cage1_3505_MRE\mreCubes1','ventricles.mat'));
You forgot the tic marks around the folder string; MATLAB tried to evaluate the \ as the ldivide, .\ operator.
You forgot quotes. Corrected:
load(fullfile('E:\charite\Data\EGCG_Round3\MRE\MouseAtlasReg\ProcessedShort\20241024_sl_MRE_Day18_Cage1_3505_MRE\mreCubes1','ventricles.mat'));
or simply don't use fullfile(), unless you need to change the folder or basefilename and are using variables for that:
load('E:\charite\Data\EGCG_Round3\MRE\MouseAtlasReg\ProcessedShort\20241024_sl_MRE_Day18_Cage1_3505_MRE\mreCubes1\ventricles.mat');

Categories

Find more on Programming in Help Center and File Exchange

Asked:

on 11 Nov 2024

Commented:

on 12 Nov 2024

Community Treasure Hunt

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

Start Hunting!