unable to plot

2 visualizaciones (últimos 30 días)
kyle lyth
kyle lyth el 6 de Mayo de 2011
hi i want to load multiple sets of data in a loop and the plot a linear graph each time the loop runs below is my code so far, i cant seem to load any variable from the file names, the variable are for example int_force=[1;2;3;4;5] deflection=[1;2;3;4;5]
function load_data
clear all
clc
%determins the number of saved files in directory
graph = dir('internalforce_*');
k = size(graph);
%starts a loop to load increase values of eg, internalforce_1,
%internalforce_2...
for i = 1 : k(1)
file_name = sprintf('internalforce_%d',i)
variable = load(file_name,'int_force')
file2_name = sprintf('deflection_%d',i)
variabletwo = load(file2_name,'deflection')
plot(variable,variabletwo)
hold on
end
end

Respuesta aceptada

Walter Roberson
Walter Roberson el 6 de Mayo de 2011
You can only specify a variable name to load() if you are loading from a .mat file, and in that case, it would always be a structure array that would be returned, thus requiring
plot(variable.int_force, variabletwo.deflection)
If the files are plain text then you must omit the variable name from the load(), but can otherwise use your code as-is.
  1 comentario
kyle lyth
kyle lyth el 7 de Mayo de 2011
thank you adding the . extensions makes sense and works great :D

Iniciar sesión para comentar.

Más respuestas (1)

Paulo Silva
Paulo Silva el 6 de Mayo de 2011
If MATLAB doesn't throw out errors when running that code that's because you are loading something correctly, please look at the workspace variables and the command line outputs, also never use the hold on command inside the loop, you just need to use it once before the loop and after creating the axes.
axes
hold on

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by