Import single raws from excel using the find function.

Hi, I have an assignment where the user should type a year, and the program should return the winner of the Eurovision Song Contest that year, with the song and country ect. All of this data is stored in a excel worksheet, and the interesting information from a specific year is stated on one raw. for example
1958 Nederland Frankrike "Dors, mon amour" André Claveau
1959 Nederland Frankrike "Dors, mon amour" André Claveau
1960 Nederland Frankrike "Dors, mon amour" André Claveau
First I'll imported the data:
[~, ~, raw] = xlsread('ESCvinnere-2','A1:E64');
[~, ~, Vertsland] = xlsread('ESCvinnere-2','B2:B64');
[~, ~, Sang] = xlsread('ESCvinnere-2','D2:D64');
[~, ~, Vinner] = xlsread('ESCvinnere-2','C2:C64');
[~, ~, Bandartist] = xlsread('ESCvinnere-2','E1:E64');
[~, ~, aar] = xlsread('ESCvinnere-2','A1:A64');
And I'll use the input command to let the user type in a number for the year. I then don't understand how I can let the find function import the current raw from the worksheet to the command window.

답변 (2개)

Thorsten
Thorsten 2015년 10월 1일
편집: Thorsten 2015년 10월 1일
You should use the first return values from xlsread to read numberical data, such as
year = xlsread('ESCvinnere-2','A1:E64');
and the second value to read text data, such as
[~, Vertsland] = xlsread('ESCvinnere-2','B2:B64');
Then you can find the index for year y (given by user) as
idx = find(year == y);
And then use this index to address the other values
Vertsland{idx}
If this is not what you want, it would be helpful to upload the xlsfile.

댓글 수: 1

yes something like that. I'll have tried that command, but i only get an error statement:
Undefined function 'eq' for input arguments of type 'cell'.
Error in stud234093b (line 18) idx = find(year == y);
I'm attaching the excel document, if this will make you smarter=), thanx for all help, I really appreciate it.
When I will managed to import the correct row and column, I'm going to use the disp function, and print :
First the input command: Enter the year with four digits: 2009 **************************************** *****************
then the disp function:
Eurovision Song Contest in 2009 was held in Russia. The winner was Alexander Rybak from Norway with the song "Fairytale".
If this helps=)?
thnx....

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

Frank Larsen Klippenberg
Frank Larsen Klippenberg 2015년 10월 1일

0 개 추천

I got it :-D Now I'm strugeling with another problem, when I'm trying to "disp", it state that:
Index exceeds matrix dimensions.
Error in stud234093b (line 20) disp(['Eurovision Song Contest ble i',num2str(y),' arrangert i',txt(r,c+1),...
any suggestion?

댓글 수: 2

What codes did you use for making the program? Im still a little bit off atm.
I'm sorry for late reply. Did you make it? The trick is to use cell2mat, do convert the data from the excel sheet to a matrise.

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

카테고리

태그

질문:

2015년 10월 1일

편집:

2015년 10월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by