![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/180194/image.jpeg)
Variation in parameter w by plotting a graph
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I am trying to plot a graph in order to show how the parameter w varies.I have used the following commands but there is an error saying that the vectors are in different length.Can anyone spot out what have I done wrong,please?
clear all; Unimodal=[28,42,46,49,52,55,58,61,64,68,82]; c=length(Unimodal) a=max(Unimodal) b=min(Unimodal) [~, ~, rank] = unique(Unimodal) w=[0.3,0.4] figure; for j=1:length(w) for i=1:c S(i)=Unimodal(i) R(i)=(S(i)-b)/(a-b) F(i)=(rank(i)-1)/(c-1) J(i)=w(j)*R(i)+(1-w(j))*F(i) scaling(i) =7 * mat2gray(J(i)) plot(Unimodal,scaling); xlabel('Prices'); ylabel('Expensiveness'); title('Varying in w in Unimodal') end end
0 Commenti
Risposta accettata
YT
il 16 Dic 2017
Is this what you wanted?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/180194/image.jpeg)
You almost had it. The problem is, you tried to plot the 'Unimodal' with a fixed length of 11 against 'scaling' with a variable length (changing on every iteration). I did it like this:
clear all;
close all;
Unimodal = [28,42,46,49,52,55,58,61,64,68,82];
c = length(Unimodal) ;
a = max(Unimodal) ;
b = min(Unimodal) ;
[~, ~, rank] = unique(Unimodal) ;
w = [0.3,0.4];
for j = 1:length(w)
for i = 1:c
S(i) = Unimodal(i);
R(i) = (S(i)-b)/(a-b);
F(i) = (rank(i)-1)/(c-1) ;
J(i) = w(j)*R(i)+(1-w(j))*F(i) ;
scaling(i,j) = 7 * mat2gray(J(i)); %saving on (i,j) position of scaling
end
end
%plotting outside loop
figure();
plot(Unimodal,scaling);
xlabel('Prices');
ylabel('Expensiveness');
title('Varying in w in Unimodal')
legend('w1','w2');
Più risposte (0)
Vedere anche
Categorie
Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!