Error in reading dimensions of a .mat file
2 visualizzazioni (ultimi 30 giorni)
q is a matrix of 1*96. f_s is a matrix of 7*1. I am getting an error saying : index exceeds matrix dimensions.
And also the maximum value i = 1 and j=46 and e_dist matrix obtained is a 1*46 matrix. Expected values of i=7, j=96 and e_dist should be a 7*96 matrix.
f_s = 'C:\Users\Toshiba\Desktop\friday work\';
q = 'C:\Users\Toshiba\Desktop\friday work\1_1_2.mat';
s = dir(f_s);
s([s.isdir]) = ;
Walter Roberson il 17 Giu 2012
creates "word" as a string, which is a row vector of characters. But then your line
attempts to access the i'th row of that character array; when "i" reaches 2, there will not be a 2nd row of the string and so you will get index exceeding matrix dimension.
Your "q" is not a matrix of 1*96: it is a character vector of 1*46 or so. Your "f_s" is not a matrix of 7*1: it is a character vector of 1*37 or so.
is calculating the Euclidean distance between file names.
It appears you have confused file names with the contents of the file.
Image Analyst il 17 Giu 2012
You need to call load(). Do it once for your reference mat file, then in the loop, do it for all the other files. Something like (untested)
folder = 'C:\Users\Toshiba\Desktop\friday work\';
refFileName = fullfile(folder, '1_1_2.mat');
if ~exist(refFileName, 'file')
errorMessage = sprintf('Error: reference file does not exist:\n%s', refFileName);
% Get the reference array.
storedStructure = load(refFileName);
refImage = storedStructure.myImage; % or whatever.
filePattern = [folder, '*.mat'];
matFilenames = dir(filePattern);
% Loop over the other arrays and compare to the ref image.
for k = 1 : numberOfFiles
thisFileName = fullfile(folder, matFilenames(k).name);
storedStructure = load(thisFileName);
thisImage = storedStructure.myImage; % or whatever.
differenceImage = double(refImage) - double(thisImage);
rmsDifference(k) = sqrt(sum(differenceImage(:)));