필터 지우기
필터 지우기

Column vector consisting of n words containing random numbers

조회 수: 2 (최근 30일)
Marcel Król
Marcel Król 2020년 6월 6일
댓글: Image Analyst 2020년 6월 7일
I am working for Matlab for the first time, so can you please solve this task step by step? task: Create a column vector A consisting of n words containing random numbers. Then create a column vector B in which the words from the vector A are sorted in ascending order. Show results in the chart.
Please help

채택된 답변

Image Analyst
Image Analyst 2020년 6월 6일
Did you try randi(), randperm(), sort(), or strsplit()? Because it's pretty easy:
txt = 'Create a column vector A consisting of n words containing random numbers. Then create a column vector B in which the words from the vector A are sorted in ascending order. Show results in the chart.'
words = strsplit(txt)
n = 5
% Choose the rule for the random numbers:
r = randi(length(words), n, 1) % Can possibly repeat
r = randperm(length(words), n) % No repeats
A = words(r)'
B = sort(A)
  댓글 수: 8
Marcel Król
Marcel Król 2020년 6월 7일
I promise, the last question;) when I want to show results in the chart, I should give : plot(A,B)?
Image Analyst
Image Analyst 2020년 6월 7일
I'd probably just loop and use fprintf() to print them out. Unless you think it wants a uitable control, like a spreadsheet.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by