sorting 2d by double value.
Ältere Kommentare anzeigen
I am getting file address on each iteration
I am trying to save in 2darray using this:
2darr(i,1) = string(file.name);
2darr(i,2) = doubleValue
Later after iteration is completed I’ll sort 2darr by doubleValue and re-iterations using loop and display into plot in doubleValue with Descending Order also the String.
How it could be done?
Akzeptierte Antwort
Weitere Antworten (1)
Muhammad Awais Ali
am 5 Mär. 2022
1 Kommentar
Walter Roberson
am 5 Mär. 2022
files = dir(strcat(app.diradd,'\*.*'));
files is now a struct array that is a column vector of struct entries
for file = files'
The variable file will become each scalar struct entry in turn
arr(i,1) = string(file.name);
file is a scalar struct, and we know that the name field returned by dir() is a character vector, so file.name will be a single character vector, which you convert to string and store in arr(i,1)
app.extractFname = string({file.name});
file is a scalar struct, and we know that the name field returned by dir() is a character vector, so file.name will be a single character vector, which you wrap in a cell array and pass to string() . string() converts a cell array containing a single character vector into a scalar string() object. So just like arr(i,1) app.extractFname will be a scalar string object containing the name -- they will have the same content
num_files = length(app.extractFname);
scalar string object, so num_files will be assigned 1
app.score = zeros(num_files, i);
All of app.score will be overwritten with the 1 x 1 array of zeros.
Then after the loop you have
[app.score , idx] = sort(app.score, 'desc');
but every time through the loop, you overwrote all of app.score with a scalar 0, so after the loop, app.score is a scalar 0. You sort that 0 in descending order, gettting out a 0 for app.score and a 1 for idx
Kategorien
Mehr zu Computer Vision with Simulink finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!