Thread Subject: Atomic Weight

Subject: Atomic Weight

From: steven berruyer

Date: 6 Oct, 2009 23:39:04

Message: 1 of 2

Hello,

I try to right a program to calcul the atomic weight of molecules.
I have the periodic table in cells.

My prog is:

load tableperiodique

FormChim=input('Entrez dans un ensemble de cellule le symbole chimique des atomes composant la mol?cule s?par?s par des espaces: \n','s');
NbOcc=input('Entrez une matrice de m?me dimensions que la pr?c?dente contenant le nombre d''occurrence de chacun des atomes dans la formule chimique: \n')


 
 MasseAt=0;
 for el=1:length(NbOcc)
     
     for i=1:109
     
          if isequal(table_periodique{i,2},FormChim{el})
             MasseAt=MasseAt+table_periodique{i,1}*NbOcc(el);
          end
          
     end
 end

MasseAt

It's function but it's not "user friendly", because for the name of molecule, user has to write: {'O' 'H'} for example
and for the number of atom : [1 2]
I want to try to ameliorate that. I want the user have to write: H 2 O 1
but I don't know how to indicate to Matlab that H and O are letters. And how to delete the blank beetween the characters....

Is there a special function? Maybe I have to use cells...I don't know.
Does anyone can help me?

Thanks a lot

Steven

Subject: Atomic Weight

From: Ashish Uthama

Date: 8 Oct, 2009 13:05:16

Message: 2 of 2

On Tue, 06 Oct 2009 19:39:04 -0400, steven berruyer
<steven.berruyer@voila.fr> wrote:

> Hello,
>
> I try to right a program to calcul the atomic weight of molecules.
> I have the periodic table in cells.
>
> My prog is:
>
> load tableperiodique
>
> FormChim=input('Entrez dans un ensemble de cellule le symbole chimique
> des atomes composant la mol?cule s?par?s par des espaces: \n','s');
> NbOcc=input('Entrez une matrice de m?me dimensions que la pr?c?dente
> contenant le nombre d''occurrence de chacun des atomes dans la formule
> chimique: \n')
>
>
> MasseAt=0;
> for el=1:length(NbOcc)
> for i=1:109
> if isequal(table_periodique{i,2},FormChim{el})
> MasseAt=MasseAt+table_periodique{i,1}*NbOcc(el);
> end
> end
> end
>
> MasseAt
>
> It's function but it's not "user friendly", because for the name of
> molecule, user has to write: {'O' 'H'} for example
> and for the number of atom : [1 2]
> I want to try to ameliorate that. I want the user have to write: H 2 O 1
> but I don't know how to indicate to Matlab that H and O are letters. And
> how to delete the blank beetween the characters....
>
> Is there a special function? Maybe I have to use cells...I don't know.
> Does anyone can help me?
>
> Thanks a lot
>
> Steven

This is the simplest I could cook up:


str='C 1 H 3 C 1 O 1 O 1 Na 1'; %assuming strict 'symbol number' order for
input data

remainder='somethingNonEmptyToGetTheWhileLoopStarted';

while(~isempty(remainder))

     [symbol, remainder] = strtok (str); %help strtok
     str=remainder;

     [number, remainder] = strtok (str);
     number=str2double(number); %you can use number to perform
multiplications
     str=remainder;

     %To ensure you have only alphabets in symbol and numeric
     %(digit) in number, you could use is ISSTRPROP

     %We need to convert number back to a string to display it
     disp(['Element ' symbol ' is present ' num2str(number) ' time(s)']);

end

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
duplicate thread Darren Rowland 6 Oct, 2009 21:03:34
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com