ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

a question about Float64MultiArray

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

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
1

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

David Galdeano gravatar image

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

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 image Cerin  ( 2017-02-11 14:22:10 -0600 )edit

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

David Galdeano gravatar image David Galdeano  ( 2017-02-15 10:41:29 -0600 )edit
1

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

zhanghao1120 gravatar image

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 -0600

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 image dornhege  ( 2013-12-16 07:28:55 -0600 )edit

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

dornhege gravatar image dornhege  ( 2013-12-16 07:29:20 -0600 )edit
-1

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

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

Question Tools

Stats

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

Seen: 7,392 times

Last updated: Dec 16 '13