![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/180097/image.png)
apply function to all elements in a column
4 ビュー (過去 30 日間)
古いコメントを表示
Hi! So I have this function: (-1/K)*log(1-i)/L)) K is a constant L is a constant i are the elements of the column I want to apply the function to, so it is all the elements of the column... I want to apply that functions to all the elements in one column and I want the results to be displayed in another column... How can I use the for loop function in this case? Thanks!
0 件のコメント
回答 (1 件)
Raul Andres Lopez Romero
2017 年 12 月 13 日
You dont need do a loop for this only use the dot operator ./ .* this multiplies or divide the vector i element by element, this is one example
i=[0.20;0.30;0.50;0.20;0.10;0.50;0.30;0.40;0.20;0.10]
K=0.8;
L=0.2;
y=(-1/K).*(log(1-i)./L)
i(:,2)=y
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/180097/image.png)
0 件のコメント
参考
カテゴリ
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!