How to pick only one non-zero value from each row of a matrix (iterative output)
1 view (last 30 days)
Show older comments
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:
0 Comments
Accepted Answer
KSSV
on 3 Mar 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 Comments
More Answers (0)
See Also
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!