Assigning values from one array to string values of another array
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi! Im writing a script that is supposed to count votes for ideas (using 3 score categories) and then rank the ideas. The values are given by a csv file. My code currently imports the data and counts the scores for each idea (using a for loop) and stores the scores in a vector. It also counts the number of ideas that have come in, names them and stores the names as a string vactor. The vectors are the same length and the ideaname and scorevalue have the same indexes. To be able to rank the ideas I would need to connect each string value with a score number and then sort the ideas from high to low according to their scores. How do I do this?
If you happen to know neat ways to visuaise the results that would also be very valuable!
The vectors are 1x9 but the length of them are defined by a variable called NumIdeas, as I want the csv file to be editable. Currently they look like this:
ideanumber = ["idea1", "idea2", ..., "idea9"]
scorevector = [5.7065, 3.2885, 7.8947, 5.8056, 5.7619, 4.2955, 5.0740, 3.0227, 7.4564]
I tried using a table function (syntax: scoreboard = table(ideanumber, scorevector) ) but the following error message was displayed; "Error using () Unrecognised row name "idea1".
I am fairly new to Matlab and would greatly appreciate any guidance you can give :) Thank you!
댓글 수: 0
답변 (2개)
KSSV
2022년 7월 15일
ideanumber = ["idea1", "idea2","idea3", "idea4","idea5", "idea6","idea7", "idea8", "idea9"] ;
scorevector = [5.7065, 3.2885, 7.8947, 5.8056, 5.7619, 4.2955, 5.0740, 3.0227, 7.4564] ;
T = table(ideanumber',scorevector')
참고 항목
카테고리
Help Center 및 File Exchange에서 Financial Data에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!