フィルターのクリア

locating a cell from two inputs

2 ビュー (過去 30 日間)
Lauren Hough
Lauren Hough 2020 年 5 月 9 日
コメント済み: Star Strider 2020 年 5 月 9 日
if (Variable1 == 'B')
Variable3 = input('Please enter a date after 22/01/2020 in the format dd-mm-yyyy\n');
Variable4 = input('Please select a location to be analysed: China, UK, South Korea, Spain, Italy, USA\n ');
if (Variable4 == 'China')
readcell('dailytotal.csv', 'Variable3', 'China')
end
What would be the code required to take a user input of a date and a country and have it output the value from a table the corresponds to these two inputs?
I have the data in matlab as both a table and individual column vectors if that makes a difference.
I've included my attempt (it continues for the rest of the countries.)
I'm getting the error 'Unkown parameter 'Variable3'
Thanks
  2 件のコメント
Ameer Hamza
Ameer Hamza 2020 年 5 月 9 日
Can you share the format of your table? In what format the date and country values are shored?
Lauren Hough
Lauren Hough 2020 年 5 月 9 日

サインインしてコメントする。

採用された回答

Star Strider
Star Strider 2020 年 5 月 9 日
I see that you found the file and were able to open it!
Try something like this:
dailytotal = array2table(rand(5,3), 'VariableNames',{'Date','China','UK'});
Choose = listdlg('PromptString',{'Select a Country'}, 'ListString',dailytotal.Properties.VariableNames(2:end));
Country = dailytotal{:,Choose+1};
That makes referencing a particular column straightforward. (Use your own ‘dailytotal.csv’ file instead of my synthetic one that I used to test my code.)
  2 件のコメント
Lauren Hough
Lauren Hough 2020 年 5 月 9 日
amazing thank you!
If it's not too much trouble would you be able to explain what each part of this is doing? I'm very new to matlab and it's syntax and this would help me out massively for next time :)
Star Strider
Star Strider 2020 年 5 月 9 日
As always, my pleasure! I very much appreciate your compliment!
Sure!
The first assignment creates the ‘dailytotal’ table to test the code.
The second assignment uses the listdlg function to create a GUI list that allows the user to choose one or more countries. (Limit this to one if you wish. (See the example in Present Current Folder Files for Single Selection to set that.) The 'ListString' cell array uses all but the first element of the 'VariableNames' property of dailytotal’ to create the list (so it updates automatically for diifferent tables with the same essential structure, that is with ‘Date’ in the first column).
The third assignment references the appropriate column in ‘dailytotal’. The offset is necessary because the first (‘Date’) column is not included in the list.
After that, you can proceed to do the analyses on the selected country column.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by