I'm trying to sort a column based on some indexing. I tried to copy the way it was done here https://stackoverflow.com/questions/16072984/sorting-cell-array-based-on-column-double-not-char-values but for a larger cell array.
I attached my code. My code will work for textfile1 but not textfile2 because of dimension mismatch. See attached for both text files. Pretend that the input (textfile1 and textfile2) are of class cell.
This is line 32:
number_Holder2 = number_Holder2(index_Ratings);
where the size of number_Holder2 is 5x1 after being run. However, before this line of code is run, the cell is 5x2 ... which I want it to be because when line 39 is run:
sorted_DoubleArray = [list(1,2:end);number_Holder2Complete]; %concatnate
I get a dimension error in my code.
Is there a way that I can adjust line 32 so that it wont remove a column?
Edit: Not allowed to use sortrows() unfortunately.

댓글 수: 4

Stephen23
Stephen23 2018년 3월 10일
A simpler way of alphanumeric sorting the rows of a cell array of char vectors:
Mark Tenorio
Mark Tenorio 2018년 3월 10일
Our lecturer banned sortrows() for this assignment.
Stephen23
Stephen23 2018년 3월 10일
편집: Stephen23 2018년 3월 10일
@Mark Tenorio: the link I gave you is not for sortrows. I should know, I wrote it!
Mark Tenorio
Mark Tenorio 2018년 3월 10일
Not sure if your link does it but I found a way. Just use a for loop to iterate through each column and index like that instead of trying to do it in one line of code.

댓글을 달려면 로그인하십시오.

 채택된 답변

Mark Tenorio
Mark Tenorio 2018년 3월 10일

0 개 추천

Not sure if your link does it but I found a way. Just use a for loop to iterate through each column and index like that instead of trying to do it in one line of code.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

2018년 3월 10일

답변:

2018년 3월 10일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by