Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
added comments
Source Link
Amro
  • 124.7k
  • 25
  • 250
  • 466
%# initialize a matrix of zeros of same size as A currentVector = zeros(size(A)); %# find linear-indices of elements where A is non-zero idx = (A ~= 0); %# fill output matrix at those locations with the corresponding elements from A %# (we apply a formula "ceil(log10(abs(.)))" to those elements then store them) currentVector(idx) = ceil(log10( abs(A(idx)) )); 
currentVector = zeros(size(A)); idx = (A ~= 0); currentVector(idx) = ceil(log10( abs(A(idx)) )); 
%# initialize a matrix of zeros of same size as A currentVector = zeros(size(A)); %# find linear-indices of elements where A is non-zero idx = (A ~= 0); %# fill output matrix at those locations with the corresponding elements from A %# (we apply a formula "ceil(log10(abs(.)))" to those elements then store them) currentVector(idx) = ceil(log10( abs(A(idx)) )); 
Source Link
Amro
  • 124.7k
  • 25
  • 250
  • 466

currentVector = zeros(size(A)); idx = (A ~= 0); currentVector(idx) = ceil(log10( abs(A(idx)) ));