separating x and y from an equation

2 ビュー (過去 30 日間)
Areeb  Ansari
Areeb Ansari 2015 年 3 月 12 日
回答済み: Elias Gule 2015 年 3 月 13 日
after applying some mathematics I have an equation as a result in the form 2x - 3y^2. Now what I want to do is separate 2x and store it into one variable and 3y^2 and store it into another variable, is there any command to separate 2x and 3y^2 ?
  1 件のコメント
Greig
Greig 2015 年 3 月 13 日
Can you gives us some more details about what your data are and what you are doing/trying to achieve. As it stands you have given a very abstract description, which have a very simple solution, or a much more complicated one.

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

回答 (1 件)

Elias Gule
Elias Gule 2015 年 3 月 13 日
%%USE regexp to split the string
%
str = regexprep('2x-3y^2','(\d+)(\w+)','$1*$2');
str = regexprep(str,'(\w+)(\^)','$1.$2');
str = regexp(str,'-','split');
% define values for x and y
x = [];
y = [];
% store the values of x in a variable x_ and y in a variable y_
evalin('base',['x_ = ' str{1} ';' 'y_ = ' str{2} ';']); %%x_ and y_ will be created in the base
% workspace

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by