MATLAB not calculate all my data
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi, im now having some problem with my code in matlab. Firstly, i have 19 sets of subjects with each of it has 25 data in N x 3 matrix (3D data). My problem arise when i want to calculate the distance between the data it only calculate until 19th data instead of the total which is 25 for each of the sets. Means every set, it only calculate until 19th data and the rest which start from 20th until 25th data is not been calculated. The calculation is the same for all the data. May i know how could i fix my code and what should i do? I really appreciate anybody who could help to solve my problem. Thank you so much. This is how my code looks like:
for A = 1: size(set,2)
for B = 1: size(fil,2)
i = double(set{:,A}{:,B});
out{A} = squareform(pdist(i));
temp{A}= out{A};
end
d{A} = temp;
list{A} = setname{A};
end
18 Commenti
dpb
il 2 Mag 2018
OK, just wanted to be sure understood specifically which distance measure you actually wanted; within variable or between (or both, maybe).
The latter question is a detail can test when have the rest working; in general it's faster to use straight-ahead vectorized functions over bsxfun but that can be a tried alternative if the first is shown to be performance lacking (I doubt that will be the case albeit when dealing with sizable data sizes, computation time is inevitably going to be noticeable).
I don't have time this instant to finish up; should be able to find a few spare moments later tonight...but I do now think I know the problem definition and believe the implementation is now straightforward and quite a lot simplified from your first try--not that that is intended as criticism; it's easy to get lost in the weeds in cell arrays when textread is insistent upon returning everything as a cell array even when it isn't needed (or would be better if it weren't). Not much in the documentation that helps the beginner understand this (as in nothing :( ).
Risposte (1)
dpb
il 3 Mag 2018
Modificato: dpb
il 3 Mag 2018
Was too tired last night; building fence is tough work for old men... :) Got 3 mi in; only 3 mi more to go... :)
Try the following to see if will read your data successfully...you'll end up with a 4D array of a series of 3D arrays which are stacked (planes) of 25 81x3 2D arrays if I didn't screw things up.
% calling folder and data directory
N=81; M=3; % size of data array of position data
projdir = 'FaceData';
d=dir(projdir); % use a name for the dir() struct
d=d(~ismember({d.name},{'.','..'})); % remove the current, parent references
s=d([files.isdir]); % the subdirectories to traverse (shorter name)
S=length(s); % number subdirs (19)
f=dir(fullfile(s(1).folder,s(1).name, '*.DATA') ); % directory for first to find F
F=length(f); % number files each subject (25)
data=zeros(N,M,S,F);
for j=1:S
f=dir(fullfile(s(j).folder,s(j).name, '*.DATA') ); % directory for each
for k=1:F % over found files in the folder
fname=fullfile(f(k).folder,f(k).name); % fully-qualified filename
data(:,:,k,j)=dlmread(fname,'delimiter',' '); % read data; save in 4D array
end
end
dataname= {s.name}.'; % save the subdirectory names
NB: I really don't like the hardcoded sizes as a general rule but it appeared that your cases are pre-ordained to be of a known size so it's probably not too bad. If there is need to have variable numbers/sizes, we can deal with that going forward one way or another; if absolutely had to could go back to cell arrays but just not so deeply entwined; just one level instead of three! :)
To then do the distances, we'll just walk through the array backwards from the last dimension across the 19 subject sets to the 25 observations from which can call pdist for each array in turn.
But, let's fix any typos/etc., I've made here first...
4 Commenti
dpb
il 3 Mag 2018
OK, came in for a break; try the above and see if it does read your data and return the data and datename arrays. It would be surprising if I didn't make a typo or other gaffe without having any data to test, but should be close...if it does happen to run, then make a .mat file of that array and attach it and I can work on the next step with real data instead of made up. If it doesn't work and you can't see an obvious error and correct it, attach the full error text and I'll try to look back in later on tonight.
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


