Hello all,
I am having difficulties getting to add to a matrix. I created an empty matrix named "bob". I have a 6 column matrix called "RPLIDARdata" that I want to pull the entire row out if a condition is met and put it in "bob". I want it to concatenate into the new matrix. "r" is the variable that I want to check and "i" is the iteration number in a for loop. The code I have tried goes as follows:
if r(i) > 1
RPLIDAR(i,:) = bob(i,:);
end
(Yes, I know that my first code wouldn't have worked.) it throws this error
%Index exceeds matrix dimensions.
Error in fcmclusteringandoccupancymap (line 28)
RPLIDAR(i,:) = bob(i,:);
I discovered vertcat so I entered this code in
vertcat(RPLIDARdata(i,:),bob)
I get this error
Error using vertcat
Dimensions of matrices being concatenated are not consistent.
Error in fcmclusteringandoccupancymap (line 28)
vertcat(RPLIDARdata(i,:),bob);
Can anyone please help me with this? I would like for this to concatenate

댓글 수: 3

Jan
Jan 2018년 5월 24일
편집: Jan 2018년 5월 24일
[MOVED from section for answers] Caleb Lindhorst wrote:
I wanted the code to do this:
data = [0 2 3
1 3 6
2 8 5]
("r" values are in third column)
if r(i) > 3
put it into a new matrix "bob"
bob = [1 3 6
2 8 5]
I eventually figured it out. The code I used goes like this
if r(i) > 1
bob = vertcat(bob,data(i,:))
It really helps filter my data and works great. "data" is the original data.
Jan
Jan 2018년 5월 24일
편집: Jan 2018년 5월 24일
This looks like an iterative growing array. This is very inefficient. What is "i"? Did you read my answer? I still assume that this is easier - without a loop:
bob = data(r > 1, :)
Caleb Lindhorst
Caleb Lindhorst 2018년 5월 24일
Sorry, Jan I didn't read it because I thought I got it figured out. I did but not as efficiently as what you have. Thank you for your help.

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

 채택된 답변

Jan
Jan 2018년 5월 23일
편집: Jan 2018년 5월 23일

0 개 추천

Do you mean:
bob = RPLIDAR(r > 1, :)
? If not, please post a small example of the inputs and the wanted output.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

릴리스

R2017a

질문:

2018년 5월 23일

댓글:

2018년 5월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by