unable to plot

2 ビュー (過去 30 日間)
kyle lyth
kyle lyth 2011 年 5 月 6 日
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

採用された回答

Walter Roberson
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 件のコメント
kyle lyth
kyle lyth 2011 年 5 月 7 日
thank you adding the . extensions makes sense and works great :D

サインインしてコメントする。

その他の回答 (1 件)

Paulo Silva
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

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by