フィルターのクリア

How to write values in a single array

3 ビュー (過去 30 日間)
lilly lord
lilly lord 2022 年 7 月 5 日
コメント済み: lilly lord 2022 年 7 月 6 日
a=[11 23 165 200 213];
a1=de2bi(a,8,'left-msb');
out1=[];
for i=1:length(a)
k= mat2cell(a1(i,:),1,[4,4]);
k1=bi2de(cell2mat(k(1)))
k2=bi2de(cell2mat(k(2)))
out1(i,:)=[k2 k1]
end
output
out1 =
13 0
14 8
10 5
1 3
10 11
a1 is
0 0 0 0 1 0 1 1
0 0 0 1 0 1 1 1
1 0 1 0 0 1 0 1
1 1 0 0 1 0 0 0
1 1 0 1 0 1 0 1
k1 and k2 are not in left-msb
I am facing two problems.
1) since left-msb is used in 2nd line(no problem here) but when I split it and convert it into decimals I am getting half left-msb and half right-msb.
2) Secon I want to write the output in a single row like [13 0 14 8 10 5 1 3 10 11].
  1 件のコメント
Walter Roberson
Walter Roberson 2022 年 7 月 5 日
2.
%to convert out1 to row form
out1 = reshape(out1.', 1, []);

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

採用された回答

Voss
Voss 2022 年 7 月 5 日
Here's a guess at what result you want to see for problem 1:
a=[11 23 165 200 213];
a1=de2bi(a,8,'left-msb');
out1=[];
for i=1:length(a)
k= mat2cell(a1(i,:),1,[4,4]);
k1=bi2de(cell2mat(k(1)),'left-msb'); % make k1 and k2 left-msb like a1 is?
k2=bi2de(cell2mat(k(2)),'left-msb');
out1(i,:)=[k2 k1];
end
out1 = reshape(out1.',1,[])
out1 = 1×10
11 0 7 1 5 10 8 12 5 13
Another way to do the same:
a=[11 23 165 200 213];
a1 = dec2bin(a,8) - '0';
n = numel(a);
out1 = zeros(n,2);
for i = 1:n
out1(i,2) = polyval(a1(i,1:4),2);
out1(i,1) = polyval(a1(i,5:8),2);
end
out1 = reshape(out1.',1,[])
out1 = 1×10
11 0 7 1 5 10 8 12 5 13
  1 件のコメント
lilly lord
lilly lord 2022 年 7 月 6 日
Thank you sooo much sir

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeIntroduction to Installation and Licensing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by