필터 지우기
필터 지우기

Replacing values in a table

조회 수: 6 (최근 30일)
Rylan Thronburg
Rylan Thronburg 2019년 4월 7일
편집: per isakson 2019년 4월 8일
Hi, I need to replace all numerical values in this table with a ranking of 5 through 1, but I can't use the city names associated with the numbers because my code has to be able to work for different data sets.
Location EndAvg
___________________ _________
'Oklahoma City, OK' [ 7.5000]
'Buffalo, NY' [ 7.8000]
'Wichita, KS' [ 8.6000]
'Rochester, MN' [ 8.8000]
'Abilene, TX' [10.9000]
This is my table, and I need to replace 7.5 with 1, 7.8 with 2, 8.6 with 3, and so on. But say there were 7 cities, I would need it to be ranked from 1-7. How do I get this done?

답변 (1개)

Walter Roberson
Walter Roberson 2019년 4월 7일
[sorted_vals, sortidx] = sort(YourTable.EndAvg);
YourTable.Rank = sortidx;
  댓글 수: 2
Rylan Thronburg
Rylan Thronburg 2019년 4월 8일
This doesn’t seem to work, unless I’m just using it wrong.
Walter Roberson
Walter Roberson 2019년 4월 8일
The above would create a new variable named Rank in the table. You could replace EndAvg by assigning to YourTable.EndAvg instead of to YourTable.Rank

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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by