How to plot multi data set in matlab?

1 次查看(过去 30 天)
Hello, I am facing a problem with plotting the graph. I wish to plot the graph in the iteration as for loop is using in my coding. I had a data set,a with 8 variables, which made to 300x8 matrix, while another set of data,w is 1x8 matrix and w is updating for every iteration. But sometimes the w may update or increase more than 1 row in the coding. I just want to plot the a and w for every iteration in same plot. Can the w that changes for every iteration plot as line graph. Here is my full coding, maybe can have a look. When I run the code, it encounter error that the matrix length is different. I wish to run it in live script because need to record video. Thank you.
clc
index=0;
load ('S1.mat')
load ('var.dat','-mat');
learning_rate=0.001;
data_size=size(Untitled);
for i=1:data_size(1)%%indicating size of matrix S1 row
current_reading=Untitled(i,:);
index=index+1;
neuron_matrix_size=size(w);
for j=1:neuron_matrix_size(1)%%indicating size of matrix w row
for k=1:neuron_matrix_size(2)%%indicating size of matrix w column
square_distance=((current_reading(k)-w(j,k)).^2);
end
euc_distance_neuronj=sqrt(square_distance);
if j==1
euc_distance = [euc_distance_neuronj];%%this is the first time create this matrix
else
euc_distance = [euc_distance euc_distance_neuronj];%%this is when the matrix has been created
end
end
%%find the best matching neuron and determine which neuron win
[minimum_distance,winning_neuron] = min(euc_distance);
%%disp(euc_distance,'euc_distance')
%%disp(minimum_distance,'minimum_distance = ')
if minimum_distance<0.05
h(winning_neuron)=h(winning_neuron)+1;
%%update weight
for k=1:neuron_matrix_size(1)
w(k,winning_neuron)=w(k,winning_neuron)+learning_rate*(current_reading(k)-w(j,k));
end
else
%%disp(w,sensor_reading)
h = [h 1];
w = [w;current_reading];
end
plot(i,Untitled);
hold on;
plot(i,w);
end

回答(0 个)

类别

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

标签

Community Treasure Hunt

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

Start Hunting!

Translated by