Bar Graphing the results of two Switch statements
Show older comments
Hello,
I am making a program that involves two switch statements and the entire periodic table. The program goes from switch statement #1, Pick a group from the periodic table, pick an element within that group, enter mass of the element and then it will calculate the number of atoms in the said amount of grams of the element. Then it goes directly to switch statement #2 and the same process happens all over again. My objective is to let the user pick two elements, set a mass for both of them, find how many atoms are in the grams of the selected elements and show a bar graph. I was hoping if someone knows how I can take those two results and put them in a bar graph so I could compare them vertically on a Y-axis. Here is what I have so far.
Thanks Edwin.
Accepted Answer
More Answers (1)
Christiaan
on 10 Mar 2015
Hello Edwin,
What you could do is to add a line for each case, where the calculated amount of atoms is defined in only one variable. Repeat this for choice 2.
Then, since it is good to know which element you have chosen in the end, you could also add for each case a string, that you know which element is chosen.
An example how it could look like is this:
switch elegr1
case 1
massofH = input('Enter mass of Hydrogen in grams:');
numofHatoms = (massofH/H)*Avosnum;
fprintf('There are %g atoms in %g grams of Hydrogen \n;',numofHatoms,massofH);
numofatoms_choice1 = numofHatoms; label_choise1='Hydrogen';
case 2
If you have done this, in the end of the m-file you will have for choice 1 and 2, not only the amount of atoms but also which atom it is.
Then you can easily use the bar plot, to plot the results. (and use a legend which atom it is)
Good luck! Christiaan
Categories
Find more on Particle & Nuclear Physics in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!