collect and extract numbers to/from number

1 回表示 (過去 30 日間)
Majid Al-Sirafi
Majid Al-Sirafi 2015 年 1 月 9 日
コメント済み: Majid Al-Sirafi 2015 年 1 月 13 日
Hi everyone how to collect some numbers (ex: 10,23,14,17 ) to be one number for example be 200 (according to ciphering method)and how to extract these four numbers from 200 number (according to deciphering method)
regards
  1 件のコメント
Geoff Hayes
Geoff Hayes 2015 年 1 月 10 日
編集済み: Geoff Hayes 2015 年 1 月 10 日
Majid - please describe why are attempting this. Do you have algorithm already that will somehow map four (or more or less) numbers to a single number, which you will then decode back to the original four? Are your numbers always two digits, or can they be 1 or 5 or 342? What is the range of your input numbers - is it from 0 to 256?

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2015 年 1 月 10 日
Try using inputdlg to get the 4 numbers. Call them a, b, c, and d. Then just do your algorithm, for example
a=10;
b=23;
c=14;
d=7;
% Encode by stitching together.
string = sprintf('%2.2d%2.2d%2.2d%2.2d', a,b,c,d)
number = str2double(string)
% Decode
aRecovered = int32(number/1e6)
bRecovered = mod(int32(number/1e4), 100)
cRecovered = mod(int32(number/1e2), 100)
dRecovered = mod(int32(number), 100)
In the command window:
string =
10231407
number =
10231407
aRecovered =
10
bRecovered =
23
cRecovered =
14
dRecovered =
7
  1 件のコメント
Majid Al-Sirafi
Majid Al-Sirafi 2015 年 1 月 13 日
Thanks dear image analyst till now, It is useful for me
best regards;
Majid

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

タグ

タグが未入力です。

製品

Community Treasure Hunt

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

Start Hunting!

Translated by