I am trying to create a constant yline (for mean) on my plot, where the value is derived from a 1x9 vector named 'Average'. I will then want to repeat this for the standard deviation value as well. I basically need it to take the value from the first column in that vector and use that value to plot the line.
figure;
plot(SortedData_Cement(1,:)),(SortedData_Cement(9,:))
xlabel('Cement (kg/m3)');
ylabel('Compressive Strenth (MPa)');
yline(Average(1),'-.g','Average');
yline(StandardDev(1),':r','Standard Deviation');
grid on
grid minor;
I have attached the output for my code above and it looks ok, but it is providing an answer everytime. I do not want a return result, just the plot image.
ans =
116.0000 173.0000 0 192.0000 0 909.8000 891.9000 90.0000 31.0237
How do I stop this from returning the above?

1 Comment

The output should comes from other code which you does not shown here.

Sign in to comment.

 Accepted Answer

As you can see the ans does not come from the piece of code you provided but must be somewhere else.
The values appear to be cooming from SortedData_Cement so, most probably, you missed a ";" when you defined this variable.
Please provide the previous code for a more precse answer and also allow me to highlights some suggestions as comments in the code below.
SortedData_Cement = [116 173 0 192 0 909.8 891.9 90 31.0237];
Average = mean(SortedData_Cement);
StandardDev = std(SortedData_Cement);
figure;
% When you want to plot a 1xN vector just do without needing to specify the
% range:
plot(SortedData_Cement);
% Same thing for plotting one value only, you don't need parenthese:
yline(Average,'-.g','Average');
yline(StandardDev,':r','Standard Deviation');
xlabel('Cement (kg/m3)');
ylabel('Compressive Strenth (MPa)');
grid on
grid minor;

4 Comments

Thank you for responding, but I don't think this works.
I have a matrix 1030x9, I have used this code to sort the table by ascending order in column 1:
SortedData_Cement = sortrows(ConcreteData1,1,'ascend');
I also calculated the values for each column 1-9 using this code:
Average_save = mean (ConcreteData1)
It gave me a result that is a vector:
[281.161 73.89 54.18 181.56 6.20 972.91 773.58 45.61 35.81]
I now need to take the value for column 1 (281.161) in the vector and that is the value I am plotting my yline againt.
Test.
plot([3 1 4 1 5 9 2 6])
yline(3)
Notice that neither plot() nor yline() output any numbers to the window. Therefore, it is not yline() that is displaying the numbers.
(You can jump through some hoops to force yline to display some numbers, but it would take multiple deliberate steps to get the kind of output you are showing us.)
Ok that makes sense, thank you - I will go back and review my earlier code!
I have found the error - thank you!

Sign in to comment.

More Answers (0)

Categories

Find more on Functions in Help Center and File Exchange

Products

Release

R2022a

Community Treasure Hunt

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

Start Hunting!