For loop update matrix

1 次查看(过去 30 天)
In my for loop i want to create and append the elements in a column vector everytime i run the function.

采纳的回答

Star Strider
Star Strider 2014-6-6
From my previous Answer to your similar question:
for k2 = 1:2 % Simulate two function calls
a = 30; % Input argument
b = 400; % Input argument
k1i = 0; % First line of actual function
filex = 0; % File doesn’t exist at first
filename = 'input_data_file.mat';
if exist(filename,'file') % If file exists, load it
load(filename)
k1i = mtrx(end,1); % Find previous end index value
filex = 1;
end
for k1 = k1i+1:(k1i+a) % Loop to create this version of ‘mtrx’
mtrx(k1,:) = [k1 b];
end
if filex == 1 % If file exists, append to it, if not create it
save(filename, 'mtrx', '-append')
elseif filex == 0
save(filename, 'mtrx')
end % Last line of function (other than its own ‘end’ statement)
fout = fopen('input_data_textfile.txt', 'w+');
fprintf(fout, '%d ', mtrx') % Write text file
end
  6 个评论
Victor
Victor 2014-6-6
For those plots, how do i control the spacing if i were to use the subplot function?
Star Strider
Star Strider 2014-6-6
I saw your Question on that and submitted an Answer. It has been the subject of several recent posts here, so I referred you to the best of those. There are also several topics in the Examples section of the documentation page for subplot.
The idea is to use the 'Position' property in each subplot and adjust it individually for each subplot.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Labels and Annotations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by