Undefined operator '-' for input arguments of type 'cell'.

1 次查看(过去 30 天)
I'm trying to input columns of data from a cell into an equation, with the hopes of it outputting multiple answers, one for each row. I've tried replacing parentheses with curly braces and using excessive parenthesis, but I can't figure it out. I'm entirely new to programming and matlab, so please go easy on me.
>> Data={'Helium','He',.0341,.0237;'Hydrogen','H2',.244,.0266;'Oxygen','O2',1.36,.0318;'Chlorine','Cl2',6.49,.0562;'Carbon dioxide','CO2',3.59,.0427}
Data =
5×4 cell array
{'Helium' } {'He' } {[0.0341]} {[0.0237]}
{'Hydrogen' } {'H2' } {[0.2440]} {[0.0266]}
{'Oxygen' } {'O2' } {[1.3600]} {[0.0318]}
{'Chlorine' } {'Cl2'} {[6.4900]} {[0.0562]}
{'Carbon dioxide'} {'CO2'} {[3.5900]} {[0.0427]}
>> Pressure=((.08206*300)/(20-{Data{:,4}}))-{Data{:,3}}/(20^2)

回答(1 个)

Image Analyst
Image Analyst 2018-9-15
Try this:
Data={'Helium','He',.0341,.0237;'Hydrogen','H2',.244,.0266;'Oxygen','O2',1.36,.0318;'Chlorine','Cl2',6.49,.0562;'Carbon dioxide','CO2',3.59,.0427}
% Data =
% 5×4 cell array
% {'Helium' } {'He' } {[0.0341]} {[0.0237]}
% {'Hydrogen' } {'H2' } {[0.2440]} {[0.0266]}
% {'Oxygen' } {'O2' } {[1.3600]} {[0.0318]}
% {'Chlorine' } {'Cl2'} {[6.4900]} {[0.0562]}
% {'Carbon dioxide'} {'CO2'} {[3.5900]} {[0.0427]}
column3 = cell2mat(Data(:, 3))
column4 = cell2mat(Data(:, 4))
Pressure = ((.08206*300) ./ (20-column4)) - column3 ./ (20^2)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by