sorting 2d by double value.
이전 댓글 표시
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?
채택된 답변
추가 답변 (1개)
Muhammad Awais Ali
2022년 3월 5일
댓글 수: 1
Walter Roberson
2022년 3월 5일
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
카테고리
도움말 센터 및 File Exchange에서 Computer Vision with Simulink에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!