Plot data in matlab

M
MattC · Mar 14, 2023 · 2K views
Question
Hi, I have 3 variables which are basically in form of % and I would like to build a trent plot for these Example:   03/06/2023 - A - 5%03/06/2023 - B - 50%03/06/2023 - C - 55% I want to plot them in the same window. Basically do not want to open them in new windows each.
Expert Answer
Profile picture of Prashant Kumar
Prashant Kumar PhD Expert
Answered Nov 20, 2025

Isn’t that just this —  

 

Scaled = @(data,Th) [data(:) ones(size(data(:)))] * ([Th 1; 0 1] \ [1; 0]);     % Scale Data By Threshold

Day{1} = [10; 
          30; 
          15];
Day{2} = [20; 
          40; 
          10];

A_Threshold = 70; 
B_Threshold = 80; 
C_Threshold = 85;
Thrshld = [A_Threshold; B_Threshold; C_Threshold];

for k1 = 1:numel(Day)
    for k2 =  1:size(Thrshld,1)
        DayScaled{k1}(k2,:) = Scaled(Day{k1}(k2,:),Thrshld(k2));
    end
end

% Day1 = array2table([DayScaled{1}].', 'VariableNames',{'A','B','C'});
% Day2 = array2table([DayScaled{2}].', 'VariableNames',{'A','B','C'});
% ScaledResult = table(Day1,Day2, 'VariableNames',{'Day 1','Day 2'})

Days = datetime(['03/06/2023';'03/07/2023'], 'InputFormat','MM/dd/yyyy', 'Format','MM/dd/yyyy');
ScaledResult = array2table(cell2mat(DayScaled), 'VariableNames',string(Days), 'RowNames',{'A','B','C'})

x = ones(size([Day{1}],2),1)*(1:size([Day{1}],1));

rgb = 'grb';
cmy = 'cmy';
xtl = {'A','B','C'};
mk = {'s','d'};
cgttt = [0.9 0.5 0.3];

figure
plot(Days, ScaledResult{:,1:end},'.-')
legend('A','B','C', 'Location','best')
ScaledResult = 3×2 table
         03/06/2023    03/07/2023
         __________    __________

    A     0.14286       0.28571  
    B       0.375           0.5  
    C     0.17647       0.11765  
x = ones(size([Day{1}],2),1)*(1:size([Day{1}],1));
rgb = 'grb';
cmy = 'cmy';
xtl = {'A','B','C'};
mk = {'s','d'};
cgttt = [0.9 0.5 0.3];
figure
plot(Days, ScaledResult{:,1:end},'.-')
legend('A','B','C', 'Location','best')

Plot data in matlab

Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!