unable to plot
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Walter Roberson
2011-5-6
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 个)
Paulo Silva
2011-5-6
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!