i have a problem with use of natsortfiles function and divide my images
1 view (last 30 days)
Show older comments
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](https://www.mathworks.com/matlabcentral/answers/uploaded_files/220435/1.png)
Accepted Answer
Stephen23
on 21 May 2019
Edited: Stephen23
on 21 May 2019
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);
More Answers (0)
See Also
Categories
Find more on File Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!