From: Jan Simon on 27 Feb 2010 09:35 Dear Juraj! > thanks, it worked almost as I needed. but I need only a few of those samples and I can't find out how to make it happen:) maybe with some for/while loop? > for k=randperm(length([face])) %here I need only a part e.g. 20 random pictures There is no need to add square brackets around your variables. This just confuses the readers. You can replace the above line by: list = randperm(length(face)); for k = list(1:20) Kind regards, Jan
From: Juraj on 27 Feb 2010 10:15 ok, I used this part, it's working fine:) ImageFiles = dir('C:\Users\yuriv\Desktop\bio\faces'); totalNumberOfFiles = length(ImageFiles)-1; scrambledList = randperm(totalNumberOfFiles); numberIWantToUse = 5; loop_counter = 1; for index = scrambledList(1:numberIWantToUse) baseFileName = ImageFiles(index).name; fprintf(1, 'File #%d = File #%d of original list = %s\n', loop_counter, index, baseFileName); loop_counter = loop_counter + 1; end but can you help me put those files(pictures) into a field like in here?: for i=1:length(faceImages) str = strcat('faces\',faceImages{i}); [face]=imread(str); [faceWidth,faceHeight]=size(face); face=reshape(face,faceWidth*faceHeight,1); for j=1:length(face) %this part i need to do faces(i,j) = face(j); end end I think it should be in that for loop, but my matlab skills are obviously more rusty than I thought:) thanks again in advance
From: us on 27 Feb 2010 10:36 "Juraj " > for j=1:length(face) %this part i need to do > faces(i,j) = face(j); > end > end > I think it should be in that for loop, but my matlab skills are obviously more rusty than I thought:) thanks again in advance a hint: - use CELLs, which you pre-allocate first... faces=cells(nr,1); % <- you must compute the # of faces NR... % instead of your FOR loop, simply use faces{i,1}=face; % <- store the current FACE in one shot... us
From: Jan Simon on 27 Feb 2010 10:42 Dear Juraj! > but can you help me put those files(pictures) into a field like in here?: > > for i=1:length(faceImages) > str = strcat('faces\',faceImages{i}); > [face]=imread(str); > [faceWidth,faceHeight]=size(face); > face=reshape(face,faceWidth*faceHeight,1); > > for j=1:length(face) %this part i need to do > faces(i,j) = face(j); > end > end Do the faces have all the same size? faces = []; for i = 1:length(faceImages) str = fullfile('faces', faceImages{i}); % Better than STRCAT face = imread(str); % No [ and ] ! if isempty(faces) % Pre-allocate !!! faces = zeros(length(faceImages), numel(face)); end faces(i, :) = reshape(face, 1, []); end It is very time-consuming to append vectors to a matrix, because Matlab has to get new memory for the new matrix for each iteration. Therefore you should ever allocate the needed memory at once! Ever ever! FULLFILE considers file separators for Unix and Windows and the user does not have to care about missing or double line breaks. Good luck, Jan
From: Juraj on 27 Feb 2010 11:06 sorry guys, now i see i didn't express myself correctly. my training & testing functions must have field inputs, that's why i need it in this part of code. it should choose random files and put them in a field in one cycle ImageFiles = dir('C:\Users\yuriv\Desktop\bio\faces'); totalNumberOfFiles = length(ImageFiles)-1; scrambledList = randperm(totalNumberOfFiles); numberIWantToUse = 5; loop_counter = 1; for index = scrambledList(1:numberIWantToUse) baseFileName = ImageFiles(index).name; fprintf(1, 'File #%d = File #%d of original list = %s\n', loop_counter, index, baseFileName); % here it should work with fields % test_faces(i,k) = face(k); ??? can it be done somehow??? % k is number of random file from face, i is main loop's cycle number, i think loop_counter = loop_counter + 1; end
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 Prev: Why it said optimization terminated?? Next: Tips on simulating on a "measured" power amplifier |