필터 지우기
필터 지우기

Unable to open file

조회 수: 12 (최근 30일)
Lauren Hough
Lauren Hough 2020년 5월 7일
댓글: Star Strider 2020년 5월 9일
(Please bare with me this is my first time coding anything at all)
I'm trying to add a feature to my code in which the user can select a country and a numerical limit and matlab will search a data set of locations and dates (dailytotal.csv) for the first value for this country that exceeds the limit and display it.
datatab = readtable('/Users/laurenhough/laurenhough/Desktop/CSV/dailytotal.csv'); %set path to the file location
datareduced = table2array(datatab(:,2:7)); %change from table format
y = {'China', 'UK', 'Spain', 'Italy', 'South Korea', 'USA'};
u = input('Please select a country in quote marks - choices are: China, UK, Spain, Italy, South Korea, USA \n');
v = input('Please define a numerical limit \n') ;
j = strcmp(y,u); %determine which column to use
%throw an error if country typed in wrong
if sum(j) == 0
error('Wrong country typed in')
end
%assume its correctly filled in, find the country column
c = find(j == 1) ;
d = find(datareduced(:,c) >= v);
%display date to screen
datatab(d(1),1)
I'm getting the error 'Unable to open file'.
What am I doing wrong?
Thanks

답변 (1개)

Star Strider
Star Strider 2020년 5월 7일
My guess is that you left out a ‘t’.
Try this:
datatab = readtable('/Users/laurenhough/laurenhough/Desktop/CSV/dailytotal.csv')
Also, I prefer inputdlg or listdlg to input. See if they could make things easier for you.
  댓글 수: 4
Lauren Hough
Lauren Hough 2020년 5월 9일
Still no luck, thanks anyway
Star Strider
Star Strider 2020년 5월 9일
My pleasure.
There may be an error in the path string (guessing here because I have no idea how you have organised your computer). Try this:
datatab = readtable('C:/Users/laurenhough/Desktop/CSV/dailytotal.csv')
Otherwise, you should be able to find ‘dailytotal.csv’ easily enough if it’s on your desktop. If it isn¹t there, and if you have Windows (which seems likely), open File Explorer and search for it there. When you find it, move it or copy it to somewhere on your MATLAB search path.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by