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

Rik
Rik 2022년 4월 12일
How do you determine the value to subtract and the indices to use?
The value to subtract is manually calculated. If I understand correctly, you mean the indices in the last row? For example for the explained line: 63 is the column where 54Fe is in the original file and 58 is the column of an element, which you use for correction.
hello
maybe it would be a good idea to share the CSV file as well
all the best

댓글을 달려면 로그인하십시오.

 채택된 답변

Rik
Rik 2022년 4월 12일

0 개 추천

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개)

카테고리

도움말 센터File Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

태그

질문:

2022년 4월 12일

댓글:

2022년 4월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by