Calculate error bar and plot them

40 visualizaciones (últimos 30 días)
Ali Tawfik
Ali Tawfik el 11 de Sept. de 2018
Editada: dpb el 16 de Sept. de 2018
Hello everyone, I have been trying to calculate the error bar, and plot them to my grouped bar.. Can anyone help as I am very new to Matlab..

Respuestas (2)

dpb
dpb el 11 de Sept. de 2018
Answer_302325 illustrates adding errorbar to a bar plot.
  8 comentarios
Ali Tawfik
Ali Tawfik el 14 de Sept. de 2018
@dpb... Are you testing me, I had really tried a lot but I could not reach to sth.. if you can help me that would be good, if you can not it's ok !
dpb
dpb el 14 de Sept. de 2018
"Testing?" No, not really, but it would be conducive to learning on your part and teaching on my part to see what seemed to be causing your troubles...if I just write code and give it, that isn't really learning anything to help your further progress.
I'll be glad to help when you show what efforts you have made...it's really not that tough; take the example at the other answer and get it to run first if nothing else...

Iniciar sesión para comentar.


Ali Tawfik
Ali Tawfik el 14 de Sept. de 2018
@ dpb... Thanks again for your clarification. But as I already had mentioned I tried and I am not cheating.. The thing is I am very new to Matlab and I'd like to understand some commands.
Thanks again
  8 comentarios
Ali Tawfik
Ali Tawfik el 15 de Sept. de 2018
Editada: dpb el 15 de Sept. de 2018
Also, I tried the new two lines,
X=cell2mat(get(H1,'XData')).'; % save first array
X=X + repmat([H1.XOffset],size(X,1),1); % add offset to each row
I got the same error +. dimensions must agree
I understand the problem not in writing the code, so I hope to understand why can not I type that ?
Hope you can figure out .. Does this code I attached worked with you ?
dpb
dpb el 15 de Sept. de 2018
Editada: dpb el 16 de Sept. de 2018
Go thru an exercise similar to what I illustrated above looking at every intermediate result.
Yes, the code works here with both my current release (R2017b) and w/ R2016b. The automagic expansion is not in R2016b I did confirm so do need the second form but it will work unless there's something else you've done that results in array dimensions not being as my illustration above.
You've got to make sure the orientation of the returned positions array X is 3x2 and that the offset vector is row vector so that the two are dimensionally compatible for the addition when expand the vector to the size of the array.
The default orientation as returned by Matlab is as I showed; it's possible your other operations may have caused something different but you'll have to just go through step-by-step to see where the difference arises and why.
Again, I would urge to "simplify, simplify!" -- start with the barest of basics -- it only takes 4-5 lines to generate the basic plot; get that to work, then worry about all the "dressing up" for presentation.
The key in coding is precision and order and sequentially analyzing every step; not just trying things willy-nilly hoping something good will happen.
There's a simple explanation for what is going on but you'll only uncover it by following each basic step from the beginning and verifying each of those is doing what you expect.
Go through the exercise as I outlined above Comment_610764 to discover where the dimension mismatch occurs. IF, as expected, that works, then you can go back and step through your code with the debugger and see where you did something that caused a different result to understand the root cause.
"Hope you can figure out."
I can't drive your terminal from here; you'll have to be the one doing the figuring; I've given you the tools and the path of breadcrumbs to follow a la Hansel & Gretel to get you through the forest... :)
ADDENDUM
Please don't take this personally; it's not aimed at you per se, but the issue of how to communicate effectively. We still have the problem that you've not shown the actual code you ran as it existed when it caused the error--you (finally!) attached an m-file several interactions back but it contains quite a lot of superfluous stuff rather than being the "bare bones".
As the note above mentions, it is precision and organization that is key; even the most trivial of detail can cause either a syntax error or a different result than that expected; we cannot debug what we cannot see and that means every change in context may be important--we can't tell what is/isn't the problem just by description or with a code line or two out of context. Again, one of the reasons why I kept bugging you to post what you had tried...

Iniciar sesión para comentar.

Categorías

Más información sobre Two y-axis en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by