How do I perform a for loop function for only one column when each number should have 10 more number created using range function?
조회 수: 3 (최근 30일)
이전 댓글 표시
Hi guys, I have a text file with the first column act as a wavelength and the second column is the intensity, the each wavelength shown in the textfile need 10 or more wavelength that is created using range function. And for the new intensity created based on the new wavelength will be using an equation. I know we supposed to used the loop function but I dont know how. I hope someone can get this thing sorted. Thank you guys!
댓글 수: 0
답변 (1개)
Hermes Suen
2018년 7월 9일
Hi, the solution depends on what you are trying to do. I assume you are trying to generate 10 or more wavelengths, and then the intensity is calculated through an equation. The first step is to create a column vector of wavelengths which can be done like so:
wavelengths = (linspace(0,500,10))';
This will create a column vector that is 10 elements long, evenly spaced between 0 and 500. I picked these numbers arbitrarily and you can adjust the code based on what wavelengths you want. The range function that you mentioned earlier returns the range of values of a given input vector. Range(x) will return the range of the values of x, and it does not seem to be what you necessarily would want.
To calculate the intensities, you would loop through the elements in the vector wavelengths.
intensity = zeroes(10,1); %Creates a column vector of length 10, all zeroes for now
for i = 1:length(wavelengths)
intensity(i) = ...%Apply the equation to: wavelengths(i);
end
Hopefully this is what you are looking for, let me know if you have any other questions
댓글 수: 1
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!