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
Torsten 2022년 2월 26일
Is it this what you want ?
A = [A,A];
C = A-B
Nimasha Pilippange
Nimasha Pilippange 2022년 2월 26일
Unfortunately not.
Torsten
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
Nimasha Pilippange 2022년 2월 27일
yes thank you for trying. I have attached the figures to make it easy to understand what I need. I need to get both of them in one scale for comparing. My attampt was shift the output 2 values to the range of output 1.
Image Analyst
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
  1. Subtract B from A, like C = A - B, or
  2. 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
Nimasha Pilippange 2022년 2월 27일
Yes I think we need scaling too. Once I get both the data in one range I need to susbstrat one from another. I attached the images again. Let me know if there is any more detail you need.
Image Analyst
Image Analyst 2022년 2월 27일
You forgot to answer my question. Which is it: 1 or 2?

댓글을 달려면 로그인하십시오.

 채택된 답변

Image Analyst
Image Analyst 2022년 2월 27일

1 개 추천

Try this:
markerSize = 30;
% Say a goes from 250 to 4800 and has 60 elements
a = 250 + (4800-250) * rand(1, 60);
% Say b goes from 100 to 900 and has 30 elements
b = 100 + (900-100) * rand(1, 30);
plot(a, 'b.-', 'LineWidth', 2, 'MarkerSize', markerSize);
hold on;
plot(b, 'c.-', 'LineWidth', 2, 'MarkerSize', markerSize);
grid on;
% Rescale b so that it also goes from 250 to 4800
b = rescale(b, min(a), max(a));
% Interpolate b so that it has the same number of elements as a.
bq = linspace(1, length(b), length(a));
b2 = interp1(b, bq);
plot(b2, 'r.-', 'LineWidth', 2, 'MarkerSize', markerSize);
% Find differences
c1 = a - b2;
c2 = b2 - a;
legend('a', 'b', 'b2')

댓글 수: 1

Nimasha Pilippange
Nimasha Pilippange 2022년 2월 28일
I used this and it seems working. Thank you very much

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Scott MacKenzie
Scott MacKenzie 2022년 2월 26일
편집: Scott MacKenzie 2022년 2월 26일

2 개 추천

Perhaps this is what you are looking for:
A=[0 0 1 1 0 0 1 1]
A = 1×8
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]
B = 1×16
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
Anew = 1×16
0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 1
Image Analyst
Image Analyst 2022년 2월 26일

2 개 추천

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.
Voss
Voss 2022년 2월 27일

1 개 추천

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에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by