dectobin ,only with loops and condition

hi,the algorithem of the action for finding binary number is dividing to 2,but in the homework description I need to define cell veriable.the new matrix is basically strings in the i,j place.example for a vector [97 ,2]___['1100001','00000010']. please help me to complete my task

回答 (1 件)

KL
KL 2017 年 9 月 19 日

0 投票

So to convert string to number,
doc str2num
and then to assign your number in a cell array
your_cell_array = {your_number}

3 件のコメント

yuval ohayon
yuval ohayon 2017 年 9 月 19 日
didn't understand you,i need to convet number to a string,and with now mat functions,you mean i need to make a function and then write main program? for the function,it will be a loop with condision first if (num~=0); num=num/2 if mod(num,2)~=0 then convertednum=1 and so on
yuval ohayon
yuval ohayon 2017 年 9 月 19 日
{function [ ] = dectobin( current_num) binary_num=CHAR(a) while (current_num~=0) last_bit=mod(current_num,2); current_num=(current_num-last_bit)/2; binary_num=lastbit;
} this is just the func,whre i use loops?main program? (for the indexed elements ,enter them to the new matrix)
KL
KL 2017 年 9 月 19 日
編集済み: KL 2017 年 9 月 19 日
If you have string inputs, first you need to convert them to numbers before doing any calculations on them (such as divide or mod).

この質問は閉じられています。

質問済み:

2017 年 9 月 19 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by