how can i insert in plot different values

1 Ansicht (letzte 30 Tage)
andrew moisidi
andrew moisidi am 25 Mai 2021
Kommentiert: andrew moisidi am 26 Mai 2021
how can i make a code that repeats the plot command and for each different iteration has different results
My Board X (20x5)
fu*nction [Y] = PlotProduct(X,Names)
for N = 1: 5;
figure;
plot(X);
title(Names{N});
xlabel('PRICES');
end

Akzeptierte Antwort

Sulaymon Eshkabilov
Sulaymon Eshkabilov am 25 Mai 2021
Hi,
Here is a simple solution:
Names={'One', 'Two', 'Three', 'Four', 'Five'};
X = randi([0, 13], 5, 15);
for N = 1: 5
figure(N)
PlotProduct(X(N, :), Names{N})
end
function [Y] = PlotProduct(X,Names)
plot(X);
title(Names);
xlabel('PRICES');
end
  1 Kommentar
andrew moisidi
andrew moisidi am 26 Mai 2021
hi
thank you but doesnt works look i have this code:
if i run it he ask me what of all these function use i type two bcs my problem is it.After matlab starting and runing the second function [Y] = plotProducts(X,Names)
and my problem is how can printing in 5 shapes (using a plot function) how the values for each product (or country) change. In the title of each shape, display the name of the product with this values( the values inside excel file)
%TELIKO PROJECT
% Author: Andreas Moisidis
% date: 22/4/21
filename = 'data.csv'; %filename of data file
%Ôï áñ÷åßï ðñÝðåé íá Ý÷åé 5 ãñáììÝò êáé 20 óôÞëåò üðùò ôï data.csv
X = csvread(filename); %Reading the data
%Ïíüìáôá ðñïúïíôùí - èá ÷ñåéáóôåß åäþ íá âÜëåôå ôá äéêÜ óáò
Names{1} = 'xiaomi redmi note 9';
Names{2} = 'xiaomi redmi 9c';
Names{3} = 'huawei p smart 2020';
Names{4} = 'xiaomi redmi 9';
Names{5} = 'samsung galaxy A21';
N = size(X,1); %N = 5
M = size(X,2); %M = 20
%èá ÷ñåéáóôåß íá áëëÜîåôå ôï ðáñáêÜôù ìýíçìá s óýìöùíá ìå ôçí åêöþíçóç
s = sprintf('Dwse 0 gia exit,\n 1 gia ektelesh ths getCurrentAverage, \n 2 gia ektelesh ths plotproduct , \n 3 gia ektelesh ths sortproduct , \n 4 gia ektelesh plotbestmodel , \n 5 gia ektelesh getCorrelated');
ok = 1;
while ok ~= 0,
ok = input(s);
a
%èá ÷ñåéáóôåß íá áëëÜîåôå ôïí ðáñáêÜôù êþäéêá óýìöùíá ìå ôçí åêöþíçóç
if ok == 0,
disp('Exit');
elseif ok == 1,
[YC,YMIN,YMAX,YA] = getCurrentMinMaxAverage(X,Names);
elseif ok == 2,
[Y] = plotProducts(X,Names);
elseif ok == 3,
[Y] = sortProducts(X,Names);
elseif ok == 4,
[Y] = plotBestModel(X,Names);
elseif ok == 5,
[a,b,c,d] = getCorrelated(X,Names);
else
disp('La8os eisodos');
end
end
-------------------------------------------------
function [Y] = PlotProduct(X,Names)
for N = 1: 5;
figure;
plot(X);
title(Names{N});
xlabel('PRICES');
end

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by