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 vue (au cours des 30 derniers jours)
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!

Réponses (1)

Hermes Suen
Hermes Suen le 9 Juil 2018
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 commentaire
Mohamad Khairul Ikhwan Zulkarnain
Modifié(e) : Mohamad Khairul Ikhwan Zulkarnain le 10 Juil 2018
Thank you! Thats really helpful. If I want to generate ten or more new wavelength from each of the existing wavelength in the copper.txt as the centre value, how do I do that? Im quite new to MATLAB and it make me confused.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by