"Rotate" 2D array

Hi all.
I'm testing a system with MLX90640 and the image is satisfying.
In order to get a valid application for my specific case, I need to rotate 90 degrees the original matrix to get landscape orientation. (for data, not only for image).
With node-red-contrib-ui-heatmap I see the target with correct 24 columns and 32 rows.
My application need to divide the columns in three groups with 8 columns each in order to verify the maximum temperature in each zone.
Actually I have convert the original 32 x 24 array in a 24 x 32 array but I need to transfer data from columns in the first array to rows in the second.
I found an example (see attached file) where it's possible to extract a single column.
Is it possible to indexing the pointer in order to extract all columns?


Extract column from 2D array.json (2.4 KB)

Sure apply the map to each index position in a for loop.

let output = []
let depth = msg.payload[0].length
// take every column
for(let i = 0; i < depth; i++){
    let col = msg.payload.map((value) => value[i]);
msg.payload= output;
return msg;

First of all, thanks for your answer.
I try to put the lines inside a function block, but the attached warning appears.
If I launch the program, the output is an empty array.
Something else to do / test to solve the question?

The warning is just a warning telling you that a function(the map) inside a loop referring to outside vars "may" cause an issue. In this case it will not, so can be ignored.

As to your result, seems strange as when i drop the function in your flow I get a result

[{"id":"e061ca3d.2e315","type":"inject","z":"bf9e1e33.030598","name":"Go","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"","topic":"","payload":"1","payloadType":"str","x":190,"y":2100,"wires":[["203e0898.9e7e2"]]},{"id":"203e0898.9e7e2","type":"function","z":"bf9e1e33.030598","name":"fill numeric array (3 x 4)","func":"//var arr =[25,19,24,18,32,31,24,12,29,22,12,14]\nvar arr = [[1,2,3],[4,5,6],[7,8,9],[10,11,12]];\nmsg.payload = arr;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":240,"y":2180,"wires":[["b6b6fec1.94c588","b8a4ae21.613328"]]},{"id":"b6b6fec1.94c588","type":"debug","z":"bf9e1e33.030598","name":"Array raw","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":490,"y":2140,"wires":[]},{"id":"b8a4ae21.613328","type":"function","z":"bf9e1e33.030598","name":"","func":"let output = []\nlet depth = msg.payload[0].length\n// take the third column\nfor(let i = 0; i < depth; i++){\n    let col = msg.payload.map((value) => value[i]);\n    output.push(col);\n}\nmsg.payload= output;\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":490,"y":2180,"wires":[["f46fae95.e94f9"]]},{"id":"f46fae95.e94f9","type":"debug","z":"bf9e1e33.030598","name":"desired column","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":730,"y":2180,"wires":[]}]



So it must be something you have added or removed, hard to tell any thing from the image you supplied.

It's my fault.
I put your sample into a different flow without formatting the input array.
Sorry for the inconvenience.
Thank you.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.