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

조회 수: 1 (최근 30일)
Joseph Salerno
Joseph Salerno 2018년 9월 15일
답변: Image Analyst 2018년 9월 15일
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