unable to plot
2 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Walter Roberson
on 6 May 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.
More Answers (1)
Paulo Silva
on 6 May 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
0 Comments
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!