The following code wont work because: I have a date1 variable array which is a double and the P_D variable seems to be a cell array. I need to set P_D to be a double variable, all numbers in the P_D variable are doubles.
Error using plot
Invalid data argument.
Error in thethird (line 54)
plot(date1, P_D(:,1))
CODE:
P_D(i,1)={Premium};
P_D(i,2)= {Call};
P_D(i,3)= {Put};
end
date1 = datenum(date,'yyyy-mm-dd HH:MM:SS');
plot(date1, P_D(:,1))
datetick('x', 'mm-dd')

댓글 수: 6

Guillaume
Guillaume 2019년 7월 21일
P_D variable seems to be a cell array
Yes, you explecitly assigned cell arrays to it. Nothing surprising there. {Premium} puts premium in a cell array.
Not knowing what's in your cell array, it's difficult to tell you how to resolve your problem. Typically, cell arrays cannot be converted to double (because they contain something other than numbers).
James Upton
James Upton 2019년 7월 21일
This answer doesnt really answer my question to be honest (no disrespect) I am asking how I set the P_D variable as a double array not a cell array. The variable only contains numbers.
James Upton
James Upton 2019년 7월 21일
The answer was use cell2mat ..........
Guillaume
Guillaume 2019년 7월 21일
The answer was use cell2mat
In that case, the cell array was probably not needed in the first place. However, as I said, it's not possible to tell you the answer without nothing more about what it is you're putting in the cell array, ie class and size of the variables you're putting into the cell array and without fulling knowing how you're creating that cell array. It looks like it may be in a loop but you haven't provided all the relevant code.
Assign into a numeric array instead.
P_D(i,1)=Premium;
P_D(i,2)= Call;
P_D(i,3)= Put;
Rik
Rik 2019년 7월 21일
Judging from the use of cells in the first place, I would guess either of the other parameters are not scalar doubles. If they are scalar doubles, then there is no need to add the complexity of a cell array.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Cell Arrays에 대해 자세히 알아보기

태그

질문:

2019년 7월 21일

댓글:

Rik
2019년 7월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by