How to pick only one non-zero value from each row of a matrix (iterative output)

2 ビュー (過去 30 日間)
Andi
Andi 2022 年 3 月 3 日
コメント済み: Andi 2022 年 3 月 17 日
Hi everyone,
My question has two parts:
Part_1: Iterative calculation
I required to repeat my iterative calculation for diffrent initial guesses. For exmaple, in the below script where i use n0=1000 as initial guess. May someone help me to mopdify this script for different initail guesses (0, 10, 100, 1000) and save the out put in a single csv file.
My script is as follow for iterative calculation:
A = readmatrix('R_mean_value_0.01.csv');
for i=1:length(A);
f = @(n)((n+1)*log(n+1)-n)/n^2 - A(i);
n0 = 10000; % Initial guess
n(i) = fzero(f,n0 );
disp(n );
end
nn=n';
csvwrite('N_mean_10000.csv',nn);
Part_2: the output matrix is consist of either non-zero values or NaN, but non-zero values are same in each row. So i wnat to pick only one non-zero values and save in another matrix. The output is liek this:

採用された回答

KSSV
KSSV 2022 年 3 月 3 日
A = readmatrix('R_mean_value_0.01.csv');
m = length(A) ;
IG = [0, 10, 100, 1000] ; % initial guess
n = length(IG) ;
nn = zeros(m,n) ;
for i = 1:n
n0 = IG(i) ;
for j=1:m
f = @(n)((n+1)*log(n+1)-n)/n^2 - A(j);
nn(i,j) = fzero(f,n0 );
disp(nn(i,j) );
end
end
csvwrite('N_mean_10000.csv',nn);
  5 件のコメント
KSSV
KSSV 2022 年 3 月 17 日
Need to check your A data...
Andi
Andi 2022 年 3 月 17 日
I double check the A (a column matrix with all positive non-zero enteries)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeArgument Definitions についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by