Info
この質問は閉じられています。 編集または回答するには再度開いてください。
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
if i have y4='0.2+6' is there a way to make p=0.2+6 but keeping the numbers like that and not equaling it to 6.2.
1 回表示 (過去 30 日間)
古いコメントを表示
if i have y4='0.2+6' is there a way to make p=0.2+6 but keeping the numbers like that and not equaling it to 6.2.
14 件のコメント
Elliott Cameron
2020 年 4 月 27 日
so y4='0.2+6' with the function inside ''. However i want to have p=0.2+6 without the '' but also i do not want p=6.2, i want p=0.2+6 staying like that and not adding together
Ameer Hamza
2020 年 4 月 27 日
Elliot, what about Walter's answer here: https://www.mathworks.com/matlabcentral/answers/520415-hello-if-i-have-two-equations-1-2x-2-and-2-3x-2-4x-7-is-there-a-way-to-remove-the-x-in-a-new-equat. Didn't it pointed you to the right direction?
Tommy
2020 年 4 月 28 日
Can you explain a bit further? Seems to me that multiplying something by (0.2) + 6 is the same thing as multiplying by 6.2. Are you hoping for the two terms to remain separate when displayed to the user?
Elliott Cameron
2020 年 4 月 28 日
multiplying something first by 0.2 and then adding 6 is not the same as multiplying by 6,2? no walters answer still had the equation within '....'
Rik
2020 年 4 月 28 日
This only makes sense in a linear concatenation of char arrays. What exact situation are you trying to use this in? I don't see how this will likely result in valid Matlab syntax. I also don't understand how this would be valid mathematics.
Elliott Cameron
2020 年 4 月 28 日
this is my demand equation demand=-0.2*x + 20 and later on i am using this find (RandData(1,:).*(-0.2)+20>RandData where this is multiplied by the slope of the line and then the intercect is added. If it were to be multiplied by 19.8 then the answer is different
Rik
2020 年 4 月 28 日
Why not leave it as a function?
demand_eq=@(x) -0.2*x+20;
result=demand_eq(RandData(1,:));
result=result>RandData;
This is much easier to understand than this.
demand_eq='(-0.2)+20';
result=zeros(1,size(RandData,2));
for n=1:numel(result)
result(n)=eval(sprintf('%.2f*%s',RandData(1,n),demand_eq))
end
result=result>RandData;
You see the train wreck that results in? You even need eval to get anything at all. You lose any option for vectorization and optimization. You also can't use other Matlab functions that accept functions as inputs.
Tommy
2020 年 4 月 28 日
Ah I did not interpret 'multiply something by (0.2) + 6' as 'multiply something by (0.2) and then add 6'. I agree with Rik. I don't think you should store this as a character vector in the first place. If for whatever reason you have to start with a character vector, I would first parse it to pull out the numbers and then go from there.
Steven Lord
2020 年 4 月 28 日
If the function to be evaluated is always going to be a polynomial, another option would be to store it as a vector of coefficients and use polyval to evalute it.
p = [-0.2, 20];
x = 0:0.25:5;
y = polyval(p, x)
One potential benefit this has over the anonymous function is that you could manipulate or query the coefficients by indexing into p.
David Goodmanson
2020 年 4 月 28 日
Hi Elliott,
could you just do something like
x = 6.2
xintdec = [floor(x) x-floor(x)]
xintdec = 0.2000 6.0000
y = xintdec*rand
y = 0.1265 3.7942
この質問は閉じられています。
回答 (0 件)
この質問は閉じられています。
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
アジア太平洋地域
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)