% Button pushed function: BUBBLEButton_3
function BUBBLEButton_3Pushed(app, event)
list = num2str(app.INPUTARRAYEditField.Value);
sorted_list = bubble(list);
app.SORTEDARRAYEditField.Value = mat2str(sorted_list);
end

 채택된 답변

Cris LaPierre
Cris LaPierre 2021년 1월 11일

0 개 추천

It looks like you are sorting characters, not numbers. Did you mean to use str2double instead of num2str? You can't enter an array in a numeric edit field, so you must be using a text one. That means your values are already strings, so num2str isn't doing anything.

댓글 수: 4

Cris LaPierre
Cris LaPierre 2021년 1월 11일
That error is saying there is a problem with your bubble sort function bubble. Specifically, the output variable, bubble_sort, is not being assigned a value.
Cris LaPierre
Cris LaPierre 2021년 1월 11일
Sorry, this appears to be one of the rare times you have to use str2num. You'll get a code analyzer warning recommeding str2double. Ignore it. When there is more than one number in the character array, it returns NaN.
Irem ERSIN
Irem ERSIN 2021년 1월 11일
Thank you so much!
Cris LaPierre
Cris LaPierre 2021년 1월 11일
If you use num2str instead of mat2str to convert it back, it won't have the brackets around it.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

질문:

2021년 1월 11일

편집:

2021년 1월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by