Installing a loop for more efficient script
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Tatjana Mü
am 12 Apr. 2022
Kommentiert: Mathieu NOE
am 12 Apr. 2022
Good Morning,
I have a csv file with 305 lines. This lines shows the measured intensitiy of elements. I need to correct interferences between the elements. The elements are saved in a string, called element_RL and the intensities are saved as doubles in intens_RL.
Therefore I am searching the element:
[~, int_elem_RL] = ismember('54Fe+', element_RL);
Then I am saving its intensity:
intens_int(:,1)=intens_RL(:,int_elem_RL);
And in the following I calculate the interference and safe the new intensity:
intens_RL(:,63)=intens_int(:,1)-0.028.*intens_RL(:,58);
So I am doing this for a lot of elements and have to write around 200 lines. I wanted to ask if somebody knows how I could short this or make it more efficient, for example with a loop?
Here are more lines of my code:
[~, int_elem_RL] = ismember('54Fe+', element_RL);
intens_int(:,1)=intens_RL(:,int_elem_RL);
intens_RL(:,63)=intens_int(:,1)-0.028.*intens_RL(:,58);
[~, int_elem_RL] = ismember('58Fe+', element_RL);
intens_int(:,1)=intens_RL(:,int_elem_RL);
intens_RL(:,70)=intens_int(:,1)-2.617.*intens_RL(:,73);
[~, int_elem_RL] = ismember('58Ni+', element_RL);
intens_int(:,1)=intens_RL(:,int_elem_RL);
intens_RL(:,71)=intens_int(:,1)-0.003.*intens_RL(:,66);
[~, int_elem_RL] = ismember('64Zn+', element_RL);
intens_int(:,1)=intens_RL(:,int_elem_RL);
intens_RL(:,78)=intens_int(:,1)-0.035.*intens_RL(:,73);
My probleme is, that I dont know how to install a loop, because the lines are so individual.
Maybe somebody else has an idea. I would appreciate this.
3 Kommentare
Mathieu NOE
am 12 Apr. 2022
hello
maybe it would be a good idea to share the CSV file as well
all the best
Akzeptierte Antwort
Rik
am 12 Apr. 2022
If there is no way to determine these values, you will have to hard-code them somewhere. So you might as well do it in a cell array:
indices={...
'54Fe+',63,-0.028,58;
'58Fe+',70,-2.617,73;
'58Ni+',71,-0.003,66;
'64Zn+',78,-0.035,73};
for n=1:size(indices,1)
[~, int_elem_RL] = ismember(indices{n,1}, element_RL);
intens_int(:,1)=intens_RL(:,int_elem_RL);
intens_RL(:,indices{n,2})=intens_int(:,1)+indices{n,3}.*intens_RL(:,indices{n,4});
end
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Introduction to Installation and Licensing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!