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

1 visualización (últimos 30 días)
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:

Respuesta aceptada

KSSV
KSSV el 3 de Mzo. de 2022
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 comentarios
Andi
Andi el 17 de Mzo. de 2022
I double check the A (a column matrix with all positive non-zero enteries)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by