How do I extract a difit from a binary string
    6 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
    Robert Jones
 il 25 Feb 2024
  
    
    
    
    
    Commentato: Star Strider
      
      
 il 25 Feb 2024
            Hello,
I  need to represent a decimal by a binary string and then extract in a loop one the digit at a time.
Something like
A=45;
B=dec2bin(A):
lb=Length(B);
C=strings(lb,1);
D=convertCharsToStrings(B);
for i=1:lb
    C=substr(D,i,1) % here I need to extract the digit. the line is just pseudo code
end
The line in the loop is not working.Any ideas?
Thank you
0 Commenti
Risposta accettata
  Star Strider
      
      
 il 25 Feb 2024
        Tweaking your code — 
A=45;
B=dec2bin(A)
lb=length(B);
C=strings(lb,1);
% D=convertCharsToStrings(B);
for i=1:lb
    C(i)=B(i); % here I need to extract the digit. the line is just pseudo code
end
C
Character arrays and string variables behave differently.  The ‘D’ variable will not work the way you want it to in this context.  
.
2 Commenti
Più risposte (0)
Vedere anche
Categorie
				Scopri di più su Characters and Strings in Help Center e File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!