Inserting variable answers in cells

Trying to insert the numerical value of a variable:
clear;
clc;
syms x y z
e1 = 2*x+z == 2;
e2 = 2*y+z == 7.52;
e3 = (z/(x+y+z))*(3.76/4.76)^(-1/2)*(1/4.76)^(-1/2) == 0.0244;
[x,y,z] = vpasolve([e1, e2, e3], [x,y,z]);
l = num2cell(x);
m = num2cell(y);
n = num2cell(z);
disp(x);
I = cell(3,4);
I{1,1} = ' ';
I{1,2} = 'a';
I{1,3} = 'b';
I{1,4} = 'c';
I{2,1} = 'Moles';
I{3,1} = 'Mole Fraction';
I{2,2} = l;
disp(I);
The output of that looks like this:
So how may I have it so that the value of 'x' shows up in the 2v2 cellarray

4 件のコメント

jgg
jgg 2016 年 1 月 23 日
This seems like the wrong approach. Why not use a table instead?
LastName = {'Smith';'Johnson';'Williams';'Jones';'Brown'};
Age = [38;43;38;40;49];
Height = [71;69;64;67;64];
Weight = [176;163;131;133;119];
BloodPressure = [124 93; 109 77; 125 83; 117 75; 122 80];
T = table(Age,Height,Weight,BloodPressure,...
'RowNames',LastName)
For example, this is basically what you're trying to do, right?
Yoshi
Yoshi 2016 年 1 月 23 日
using the command "double" solved my issue
I{2,2} = double(x);
Yoshi
Yoshi 2016 年 1 月 23 日
Yes that's it! Sorry, I didn't refresh this page before posting.
Star Strider
Star Strider 2016 年 1 月 23 日
Does my Answer do what you want?

サインインしてコメントする。

 採用された回答

Star Strider
Star Strider 2016 年 1 月 23 日

0 投票

What do you want to do?
Part of the problem is that ‘a’, ‘b’, ‘c’ do not exist in your workspace.
If you want to put ‘x’, ‘y’, ‘z’ in ‘I’, do something like this:
I = cell(3,4);
I{1,1} = ' ';
I{1,2} = double(x);
I{1,3} = double(y);
I{1,4} = double(z);
I{2,1} = 'Moles';
I{3,1} = 'Mole Fraction';
I{2,2} = l;
disp(I);

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeHistorical Contests についてさらに検索

タグ

質問済み:

2016 年 1 月 23 日

コメント済み:

2016 年 1 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by