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!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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 (한국어)