필터 지우기
필터 지우기

Stacking data sets into 1

조회 수: 1 (최근 30일)
Jason
Jason 2018년 1월 26일
댓글: Star Strider 2018년 1월 26일
I am trying to stack data. I have an matrix (ROI), that I obtain the rows from. Each row is my y data. The x data is just the column number (1:num_of_columns)
for each row of data, I need to take the column number and shift it by an amount in a vector called thresh (and column2).
I then want to combine each set of data. The left graph shows the first 2 rows i plot seperately before the x-axis shift. The right hand graph is individual plots of all the rows each shifted (from the vector thresh(:,2)).
stack=[];
for i=1:num_of_rows
y=ROI(i,:);
plot(x-thresh(i,2),y,'r.'); hold on;
if i==1
stack(:,1)=x-thresh(i,2);
stack(:,2)=y;
else
stack(:,1)=vertcat(stack(:,1),x-thresh(i,2))
stack(:,2)=vertcat(stack(:,2),y)
end
end
grid on;
stack
Error using vertcat
Dimensions of matrices being concatenated are not consistent.
Error in ArchimedesIQC>pushbutton126_Callback (line 12236)
stack(:,1)=vertcat(stack(:,1),x-thresh(i,2))
  댓글 수: 3
Guillaume
Guillaume 2018년 1월 26일
No, the problem is
x(:, 1) = [x(:,1), something_not_empty]
the number of elements on the left hand side is always going to be smaller than the number of elements on the right hand side. This is always going to result in an error in matlab.
The error itself may be caused by x being a row vector instead of a column vector.
Star Strider
Star Strider 2018년 1월 26일
‘The error itself may be caused by x being a row vector instead of a column vector.’
Precisely the reason I asked for their dimensions before proceeding!

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

채택된 답변

Guillaume
Guillaume 2018년 1월 26일
편집: Guillaume 2018년 1월 26일
I have not really understood what it is you're trying to achieve but fixing your error is easy:
else
stack = [stack; x-thresh(i, 2), y]; %or vertcat(stack, [x-thresh(i, 2), y]);
end
Note that this assumes that x and y are column vectors. If they are row vectors, you need to transpose them:
stack = [stack; x.' - thresh(i, 2), y.'];

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by