Giter VIP home page Giter VIP logo

Comments (4)

tomstewart89 avatar tomstewart89 commented on July 20, 2024 1

Hey @VitorCMatias, sorry for the slow reply, and thanks for helping out @gaspatxo!

The Matrix class actually does define an operator= that accepts a float array, but it expects a 2D array whereas you've declared a 1D array. If you change your code like so then it should compile:

float numbers[3][3];
for (int i = 0; i < 3; i++)
{
    for (int j = 0; j < 3; j++)
    {
        numbers[i][j] = random(10,990) / 10.0;
    }
}
BLA::Matrix<3, 3> A;
A = numbers;

That said, unless you need to use an array for your application, I'd recommend directly setting the elements as in @gaspatxo's suggestion.

Hope that helps!

from basiclinearalgebra.

tomstewart89 avatar tomstewart89 commented on July 20, 2024

Hey @VitorCMatias, at the moment the library doesn’t have any functions to create a random matrix automatically, but you should be able to create a matrix, loop through the elements and fill them with random values.

I’m not sure what might be causing your compiler errors but can you post a minimal example of the code you’re using? I might be able to help figure the problem out

from basiclinearalgebra.

VitorCMatias avatar VitorCMatias commented on July 20, 2024

I am using this piece of code inside my void setup() function. Iam creating a array with 9 elements and then assigning it to a matrix. But I am receiving this error:
"no match for 'operator=' (operand types are 'BLA::Matrix<3, 3>' and 'float [9]')"

float numbers[3*3]; for(int i = 0; i < 3*3; i++) { numbers[i] = random(10,990)/10.0; } BLA::Matrix<3, 3> A; A = numbers;

from basiclinearalgebra.

gaspatxo avatar gaspatxo commented on July 20, 2024

Hello @VitorCMatias the error you are getting comes from trying to assign a float array to a Matrix object, that is not possible, in the same way you cannot assign string to an integer type.

What you can do is the following:

BLA::Matrix<3, 3> A; 
for(int i = 0; i < 3*3; i++)  A(i) = random(10,990)/10.0;
Serial << "- A: \n" << A << "\n";

Output:

- A: 
[[15.70,-0.05,0.05],[5.90,0.00,0.05],[38.30,1.00,0.00]]

In this case A is a 3x3 matrix, if what you are looking for is a 9x1 matrix then declare A with BLA::Matrix<9, 1> A;
Output:

- A: 
[[15.70],[5.90],[38.30],[54.80],[10.00],[42.20],[33.40],[92.80],[89.30]]

from basiclinearalgebra.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.