shift matrix to the right
古いコメントを表示
Hello,
I need to compare 2 matrices. One is 1x1280 and other is 1x5120. So I need to take the 1st one to the other range. How do i do that.
for example: A=[0 0 1 1 0 0 1 1], B=[0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1]. The number of elements in B is an integer multiple of number of elements in A. After shifting I need to subtract A by B.
Any Idea?
7 件のコメント
Torsten
2022 年 2 月 26 日
Is it this what you want ?
A = [A,A];
C = A-B
Nimasha Pilippange
2022 年 2 月 26 日
Torsten
2022 年 2 月 27 日
After so many people have tried to interprete what you mean by "shift", I think it would be fair to disclose the secret.
Nimasha Pilippange
2022 年 2 月 27 日
Image Analyst
2022 年 2 月 27 日
I don't think shifting will do it. You need scaling also.
Plus you didn't explain "subtract A by B". Does that mean
- Subtract B from A, like C = A - B, or
- Subtract A from B, like C = B - A
Which is it?
Why didn't any of the answers below work?
Your screenshots look like data that you forgot to attach. Please do so with the paperclip icon. We'll check back later for it, and for your answers.
Nimasha Pilippange
2022 年 2 月 27 日
Image Analyst
2022 年 2 月 27 日
You forgot to answer my question. Which is it: 1 or 2?
採用された回答
その他の回答 (3 件)
Scott MacKenzie
2022 年 2 月 26 日
編集済み: Scott MacKenzie
2022 年 2 月 26 日
Perhaps this is what you are looking for:
A=[0 0 1 1 0 0 1 1]
B=[0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1]
m = numel(A);
n = numel(B);
Anew(n-m+1:n) = A % shifted to match B with zeros at beginning
Image Analyst
2022 年 2 月 26 日
It appears no one knows what you mean since it's not clearly explained and you didn't give the resulting difference vector. So here is another guess:
A=[0 0 1 1 0 0 1 1];
B=[0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1];
% Resize smaller vector to be the same size as the larger vector.
a2 = imresize(A, size(B), 'nearest')
% "subtract A by B" - whatever that means. Here are two possibilities
c = a2 - B
c = B - a2
Let me know if either of these is what you want.
Maybe use interp1() (or resample()):
nx = 20;
x = randn(1,nx);
% xr = resample(x,4,1);
xr = interp1(1:nx,x,1:0.25:nx);
figure();
plot(1:nx,x,'-o');
hold on
plot(0.25*(4:numel(xr)+3),xr,'.');
legend({'Original','Interpolated x4'})
カテゴリ
ヘルプ センター および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

