Borrar filtros
Borrar filtros

Question about using 'load' to load an .m file

2 visualizaciones (últimos 30 días)
Robert
Robert el 14 de Sept. de 2012
I'm currently trying to use the load command to pull data from an existing .m file I've downloaded from the internet, but the .m file is coming in as a [0x0] vector, and it shouldn't be.
I'm getting the message
"Attempted to access sampleDataFlow(:,1); index out of bounds because size(sampleDataFlow)=[0,0]."
when I attempt to define a variable to column 1. Any idea why this would be happening?
Thanks

Respuestas (3)

Ryan G
Ryan G el 14 de Sept. de 2012
Although you can use the load command with an m-file, in my humble opinion, this would not be the ideal way to transfer data nor read data.
My suggestion would be to utilize the Import Tool available in the Home tab (R2012b). It's available in other versions but I like to be forward thinking.
This will allow you to utilize a GUI for the first time you import making it easy to determine if the data was imported correctly and easy to change the import method to achieve desired results. Once you're established the correct method you will be able to automatically generate a script or function to do it again and again.
The link above describes it better than I ever could.
  9 comentarios
Ryan G
Ryan G el 14 de Sept. de 2012
I would verify that hte data exists in the downloaded file. It sounds like the issue is coming up between downloading the file and the file that exists locally
Robert
Robert el 14 de Sept. de 2012
That's also what I think. I'm not sure what the issue would be. I'm using "save target as..." to do the download, and it hasn't ever failed me before, so I'm not sure what's going wrong. Frustrating.

Iniciar sesión para comentar.


Walter Roberson
Walter Roberson el 14 de Sept. de 2012
Try using the -ascii option when you load()

Azzi Abdelmalek
Azzi Abdelmalek el 14 de Sept. de 2012
Editada: Azzi Abdelmalek el 14 de Sept. de 2012
you can get your data like you import any text file
fid = fopen('file.m');
line1 = fgetl(fid)
res=line1;
while ischar(line1)
line1 = fgetl(fid);
res =char(res,line1)
end
fclose(fid);

Categorías

Más información sobre Downloads en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by