Ask Your Question
1

a question about Float64MultiArray

asked 2013-12-16 05:02:10 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

Hi everyone

I define my Variable as follow: std_msgs::Float64MultiArray Atest; I want to assign a value to specific element. for example i want to change value of fifth element to 5. how i can write it? Best

edit retag flag offensive close merge delete

4 Answers

Sort by ยป oldest newest most voted
0

answered 2013-12-16 08:35:28 -0500

David Galdeano gravatar image

updated 2013-12-16 21:30:54 -0500

Declare the lib:

#include <std_msgs/Float64MultiArray.h> //include the lib

use it:

std_msgs::Float64MultiArray Atest; //declare Atest
Atest.data.resize(5); //resize the array to assign to existent values
Atest.data[4] = 5; //put the desired value
edit flag offensive delete link more

Comments

This generates the error error: request for member 'resize' in 'Atest.std_msgs::Float64MultiArray::data', which is of non-class type 'std_msgs::Float64MultiArray::_data_type* {aka float*}'

Cerin gravatar imageCerin ( 2017-02-11 14:22:10 -0500 )edit

It works but maybe not in your case, as explained here: https://stackoverflow.com/questions/4...

David Galdeano gravatar imageDavid Galdeano ( 2017-02-15 10:41:29 -0500 )edit
0

answered 2019-05-19 05:00:14 -0500

Its likes a vector, dont like the array. please according to the using the way to vector, not array.

Atest.data.push_back(5.0);

edit flag offensive delete link more
0

answered 2013-12-16 06:55:58 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

it doesn't work....i've already tried it....it caused Segmentation fault (core dumped)...is it my ros problem or something else?

edit flag offensive delete link more

Comments

Please do not create answers for discussion or comments. Instead, either edit and append to your original post or use the comment functionality.

dornhege gravatar imagedornhege ( 2013-12-16 07:28:55 -0500 )edit

It's probably you fault. Have you made sure that there are 5 values?

dornhege gravatar imagedornhege ( 2013-12-16 07:29:20 -0500 )edit
-1

answered 2013-12-16 05:20:59 -0500

dornhege gravatar image
Atest.data[4] = 5;
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-12-16 05:02:10 -0500

Seen: 3,342 times

Last updated: Dec 16 '13