MATLAB Answers

0

i have a problem with use of natsortfiles function and divide my images

Asked by Elahe Karimi on 21 May 2019
Latest activity Commented on by Elahe Karimi on 21 May 2019
hello,
I used the function given in the link below to Ordered read the images in the file.
In line 53 --->There was no error because it was a structure , but now (When i used of natsortfiles function :https://www.mathworks.com/matlabcentral/answers/335698-how-to-sort-a-structure-array ) it has an error ,i think because it changed into a cell array.
To resolve this problem, I used the line 47 (structtt = cat (1, cellFileNames {:});) but the problem has not been resolved. In general, i want to read my images in folders (sorted :1,2,3,4,.....) and divide them to train and test images.
Please help me. Thank you so much
1.PNG

  0 Comments

Sign in to comment.

1 Answer

Answer by Stephen Cobeldick on 21 May 2019
Edited by Stephen Cobeldick on 21 May 2019
 Accepted Answer

It is not clear what you expect this line
structtt = cat(1,cellFileNames{:});
to do, but in actual fact it will vertically concatenate all of the filenames (i.e. character vectors) into one character array (assuming that they have compatible sizes, otherwise it will simply throw an error). I very much doubt that this character array would be particularly useful for you, nor is it a very robust way to write code. In any case, you already have exactly the same filenames in exactly the same order in the variable cellFileNames: is there any point to duplicating the same data in another variable?
Your variable names are very misleading, e.g. train_idx and test_idx would be character arrays of filenames, they would not contain any indices.
The vector idx is totally superfluous.
As far as I can tell, you are trying to do something like this:
PD = 0.5;
S = dir(fullfile(thisFolder,'*.png'));
C = natsortfiles({S.name});
N = numel(C);
X = round(PD*N);
C_train = C(1:X);
C_test = C(X+1:N);

  1 Comment

thank you so much for your guide and response.

Sign in to comment.