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

3 次查看(过去 30 天)
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 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Argument Definitions 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by