Installing a loop for more efficient script
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
Mathieu NOE
2022 年 4 月 12 日
hello
maybe it would be a good idea to share the CSV file as well
all the best
採用された回答
Rik
2022 年 4 月 12 日
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Startup and Shutdown についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!