Import single raws from excel using the find function.

1 view (last 30 days)
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.

Answers (2)

Thorsten
Thorsten on 1 Oct 2015
Edited: Thorsten on 1 Oct 2015
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 Comment
Frank Larsen Klippenberg
Frank Larsen Klippenberg on 1 Oct 2015
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....

Sign in to comment.


Frank Larsen Klippenberg
Frank Larsen Klippenberg on 1 Oct 2015
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 Comments
Emil Roaldsoy
Emil Roaldsoy on 2 Oct 2015
What codes did you use for making the program? Im still a little bit off atm.
Frank Larsen Klippenberg
Frank Larsen Klippenberg on 5 Oct 2015
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.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!