# How do I input a table column of values into a formula?

22 visualizzazioni (ultimi 30 giorni)
Macy il 6 Feb 2023
Commentato: Macy il 6 Feb 2023
Hello, I am new to MatLab. Here is some simple code I would greatly appreciate some help on.
I am given an excel spreadsheet of dates and a value of length (radius). I want to convert the radius from inches to centimeters by multiplying it by 2.54. Then I want to calculate areas using the radius, one set as inches^2 and one set as centimeters^2. I don't know how to input values from the excel column into formulas on MatLab. I get the error that operator '*' is not supported for operands of type 'table', but when I forgo '*' I get another error stating "Invalid Experssion".
clc;
close all;
clear all;
% Prepare DataSet
radius ______ 12 14 13 12 11
Operator '*' is not supported for operands of type 'table'.
%Calculate area in cm^3 and in^3, area = pi*r^2
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Chris il 6 Feb 2023
Modificato: Chris il 6 Feb 2023
The problem, as pointed out by Stephen, is that you are accessing the table data with parantheses, which creates another table. Your code will work if you use curly braces:
Here are some other options:
% Read in as a matrix, losing the variable names
Trans = 5×4
9 7 2011 12 9 8 2011 14 9 9 2011 13 9 10 2011 12 9 11 2011 11
30.4800 35.5600 33.0200 30.4800 27.9400
Trans = 5×5 table
month day year radius radiusincm _____ ___ ____ ______ __________ 9 7 2011 12 30.48 9 8 2011 14 35.56 9 9 2011 13 33.02 9 10 2011 12 30.48 9 11 2011 11 27.94
% Read in as a table, refer to variable names
30.4800 35.5600 33.0200 30.4800 27.9400
##### 2 CommentiMostra NessunoNascondi Nessuno
Stephen23 il 6 Feb 2023
"The problem is that you created a table called "radius" with a variable name "radius.""
The actual problem is that the OP used the wrong kind of indexing. To access table content use curly braces, not parentheses. The difference is explained in the MATLAB documentation:
Macy il 6 Feb 2023
Thanks!

Accedi per commentare.

### Categorie

Scopri di più su Tables in Help Center e File Exchange

R2022b

### Community Treasure Hunt

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

Start Hunting!

Translated by