How do I perform a for loop function for only one column when each number should have 10 more number created using range function?
1 次查看(过去 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!