How to naming for this? MATLAB Question

hK0='428a2f98d728ae22'; % K0~K15
hK1='7137449123ef65cd'; hK2='b5c0fbcfec4d3b2f'; hK3='e9b5dba58189dbbc'; hK4='3956c25bf348b538'; hK5='59f111f1b605d019';
hK6='923f82a4af194f9b'; hK7='ab1c5ed5da6d8118'; hK8='d807aa98a3030242'; hK9= '12835b0145706fbe'; hK10='243185be4ee4b28c';
hK11='550c7dc3d5ffb4e2'; hK12='72be5d74f27b896f'; hK13= '80deb1fe3b1696b1'; hK14='9bdc06a725c71235'; hK15='c19bf174cf692694';
for t=0:15
K=fn_hex2bin(hKt);
t=t+1;
end
ex)
1st loop
K=fn_hex2bin(hK0);
2nd loop
K=fn_hex2bin(hK1);
3rd
K=fn_hex2bin(hK2);
..
I will make each K and put another operation in for verse...
How to naming for each K?

 Réponse acceptée

Stephen23
Stephen23 le 10 Juin 2020
Numbering variables like that is not a good way to write MATLAB code. You could do that, but you force yourself into writing slow, complex, obfuscated, buggy code that is hard to debug. That approach is not recommended.
The simple, efficient, recommended approach is to use indexing, e.g. with a cell array:
C = {'428a2f98d728ae22';
'7137449123ef65cd';
'b5c0fbcfec4d3b2f';
'e9b5dba58189dbbc';
'3956c25bf348b538';
'59f111f1b605d019';
'923f82a4af194f9b';
'ab1c5ed5da6d8118';
'd807aa98a3030242';
'12835b0145706fbe';
'243185be4ee4b28c';
'550c7dc3d5ffb4e2';
'72be5d74f27b896f';
'80deb1fe3b1696b1';
'9bdc06a725c71235';
'c19bf174cf692694'};
N = numel(C);
D = cell(N,1);
for k = 1:N
D{k} = fn_hex2bin(C{k});
end

Plus de réponses (0)

Catégories

Produits

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by