Clear Filters
Clear Filters

Help with matlab Homework

3 views (last 30 days)
Jeff
Jeff on 10 Dec 2023
Answered: Walter Roberson on 10 Dec 2023
Hi :), can anyone please help me how to solve errors on my script, my code is running but some errors are coming up.
I have attached the files below.
Thank you Kindly

Answers (1)

Walter Roberson
Walter Roberson on 10 Dec 2023
  • you should be using readtable() instead of readmatrix()
  • As far as MATLAB is concerned, totalValue = sum(data, productNames); is a request to total the array data along the dimension numbers stored in productNames and that syntax absolutely will not select variable names out of an array or table
Beyond that: it turns out that the first variable in your table is named productNames and the second is named Price
If I were working with that kind of data table, I would use readtable() and tell readtable() that the first column is to used as "row names". Then I would pull out all of the row names from the table and use those in the list dialog instead of hard-coding the list dialog entries. list dialog would return the indices of the chosen items, which could then be used as indices into the Price variable of the table, getting out a vector of prices, which you could then sum. All assuming that when an item is select that exactly one of them is to be purchased.

Categories

Find more on Structures in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!