How to write values in a single array

5 次查看(过去 30 天)
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].

采纳的回答

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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Introduction 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