Conversion to logical from struct is not possible. (It's a binary matrix!)

6 次查看(过去 30 天)
myFolder = '/MATLAB Drive/saliency/code_forMetrics/dataset/test';
filePattern1 = fullfile(myFolder,'saliency', '*.jpg');
filePattern2 = fullfile(myFolder,'fixation_b', '*.mat');
imgFiles = dir(filePattern1);
fixFiles = dir(filePattern2);
for k = 1:length(imgFiles)
baseFileName1 = imgFiles(k).name;
fullFileName1 = fullfile(myFolder,'saliency', baseFileName1);
baseFileName2 = fixFiles(k).name;
fullFileName2 = fullfile(myFolder,'fixation_b', baseFileName2);
img{k} = imread(fullFileName1);
fix{k} = load(fullFileName2);
score{k} = NSS(img{k}, fix{k});
end
Output:
test_0_bfix
Error using logical
Conversion to logical from struct is not possible.
Error in NSS (line 16)
score = mean(map(logical(fixationMap)));
Error in test_0_bfix (line 14)
score{k} = NSS(img{k}, fix{k});
Since the problem doesn't seem to appear before,is this the version problem?
fixation.mat suppose to be a binary matrix
Besides,as a newbee in ML,i would like to ask how to calculate the mean of score since it's a cell.
I'd appreciate for your help.

采纳的回答

Stephen23
Stephen23 2019-6-5
编辑:Stephen23 2019-6-5
As the load documentation clearly states, if the file is a .mat file then the output of load is a scalar structure, whos fields are the variables that were saved in the .mat file. So you will need to refer to the field of that structure:
S = load(...);
F{k} = S.whateverFieldNameYourDataHas;
If there is only one variable per file and you do not know its name, then you could do this:
S = load(...);
C = struct2cell(S);
F{k} = C{1};
Note that naming a variable fix is not a good idea, as this shadows the inbuilt fix function.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Variables 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by