How do I input a matrix (variable) in a function?
2 次查看(过去 30 天)
显示 更早的评论
I created a function:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/145823/image.jpeg)
.
x is the excitation wavelength where i will input eg. " test,wavelength(765,y)"
.
y is a 729 by 1 matrix: .
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/145824/image.jpeg)
.
the result is:
.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/145825/image.jpeg)
.
where only the first number of y matrix is being implemented in the function. How do i create a function where the first number of y matrix will be implemented and return as a result as the first number in wavelengtha matrix and so on.
1 个评论
the cyclist
2014-10-22
The screenshots are very helpful in understanding your problem. I suggest not using them for the actual code, though, so that we can copy & paste your code into MATLAB ourselves.
采纳的回答
Mohammad Abouali
2014-10-22
1) why you have comma in your function name?
2) Change your equation in element wise division as follow:
wavelengtha= 1./ ((1./x)-(y/10^7))
3 个评论
Mohammad Abouali
2014-10-22
One way is to do this:
let's say x=[765, 766, 777]
then you can do this:
for i=1:numel(x) wavelengtha{i}= yourFunction(x(i), ...) end
I still don't get the comma in your function name?
更多回答(1 个)
the cyclist
2014-10-22
I'm not sure I fully understand what you mean, but does this do what you intend?
wavelengtha = 1./((1./x) - (y/10^7));
Notice that I used element-wise division.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!