I am trying to use the information already created in an Excel document to create a Plot. The location is taken directly from the properties of the Excel file but I keep getting this error. I have been trying for a while to figure this out with no luck. Any ideas what could be wrong?

1 comentario

Rik
Rik el 18 de Sept. de 2018
What does exist return for this string?

Iniciar sesión para comentar.

 Respuesta aceptada

OCDER
OCDER el 18 de Sept. de 2018
Editada: OCDER el 18 de Sept. de 2018

1 voto

Does that directory exist?
C:\Users\Anthony\Desktop\220 Lab\Intro
To check
exist('C:\Users\Anthony\Desktop\220 Lab\Intro', 'dir')
If it returns 0, that directory does not exist. You cannot change to a directory that does not exist.
Also, usage of cd change directory should be minimized, as that really is just for you to use to navigate folder while coding - not to be used in actual programming runs, unless your program is specifically designed to change user folders.
Based on what you want to do, try this:
%Let's you choose the file
[FileName, FilePath] = uigetfile('Intro.xls*', 'Open Excel file.');
if isnumeric(FileName)
error('No file was selected');
end
%Or you could just start here, but define
%FilePath = 'C:\Users\Anthony\Desktop\220 Lab\Intro'
%FileName = 'Intro.xlsx'
FullFileName = fullfile(FilePath, FileName); %assemble full file path + name
Data = xlsread(FullFileName, 1, 'A2:A16'); %DO NOT do "load = " to replace load
%load is built-in matlab function!
Def = xlsread(FullFileName, 1, 'B2:B16');
plot(Data, Def) %lowercase plot, not "Plot"

4 comentarios

Anthony Voccia
Anthony Voccia el 18 de Sept. de 2018
Thanks! I was going off what the TA wrote in lab. Just need to clean up the labels and this will be good to go
OCDER
OCDER el 18 de Sept. de 2018
Make sure your xlsread actually takes the full file name as input.
xlsread('Intro', ...) ==> xlsread(fullfile(FilePath, FileName), ...)
Anthony Voccia
Anthony Voccia el 20 de Sept. de 2018
Would that look like
data = xlsread(fullfile('C:\Users\Anthony\Desktop\220 Lab\Intro', 'Intro.xlsx'),('Intro',1,'A2:A16'))
OCDER
OCDER el 20 de Sept. de 2018
FilePath = 'C:\Users\Anthony\Desktop\220 Lab\Intro'
FileName = 'Intro.xlsx'
FullFileName = fullfile(FilePath, FileName);
Data = xlsread(FullFileName, 1, 'A2:A16');

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre File Operations en Centro de ayuda y File Exchange.

Preguntada:

el 18 de Sept. de 2018

Comentada:

el 20 de Sept. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by