Importing and Plotting Data

I have pasted 4 columns of data into a .txt file and then:
fileID=fopen('Lab5data.txt');
plot(data(:,1),data(:,2),data(:,3),data(:,4));
trying to plot all 4 on the same plot but im getting:
Undefined variable Data.
Error in Lab5Practice (line 42)
plot(data(:,1),data(:,2),data(:,3),data(:,4));
a few days ago i made a similar plot using the same method and it worked fine but today neither this nor the old one will work. I have not moved any files since then and the file path shows correct. What am i missing here?

 Respuesta aceptada

Hikaru
Hikaru el 18 de Nov. de 2014

0 votos

It's because you have not define the variable data .

5 comentarios

Paul
Paul el 18 de Nov. de 2014
I understand, im very new to MATLAB. My issue is that its the exact same method i used the other day and it worked fine. how do i define data that i imported. I thought i did that when i imported it by thinking that "data" knew it was from the import.
Hikaru
Hikaru el 18 de Nov. de 2014
Please use the comment function, and not create another answer to your own question to avoid confusion for other users.
It depends on the format of your data in the text file.
You can use, perhaps:
data = dlmread('Lab5data.txt')
or any other functions you might prefer, such as fscanf or textscan .
Image Analyst
Image Analyst el 18 de Nov. de 2014
Obviously it's not the same. You changed something. Perhaps it was the name of the variable. "Data" is different than "data" and you show both. MATLAB is case sensitive. Show your exact code and exact error message - don't snip or paraphrase or re-type. Just copy and paste all the red text.
Paul
Paul el 18 de Nov. de 2014
that did it, thanks you so much!
The comment thing was my fault, i fixed it (i think) just after i hit submit and then looked up and saw the comment function. first time user here, wont happen again.
Paul
Paul el 18 de Nov. de 2014
i used the data = dlmread('Lab5data.txt') and it worked.
seems somehow, maybe when it was saved, its capitalized "Data" as well as another thing, strange. Ill watch out for it next time.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Preguntada:

el 18 de Nov. de 2014

Comentada:

el 18 de Nov. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by