- store the index in the numeric array, or
- use another kind of array, e.g. a cell array, table, etc.
How to insert text in a matrix - If function
53 次查看(过去 30 天)
显示 更早的评论
Dear All, In the following code I would like to insert 'good news', 'bad news', 'no news' instead of 1, 2, 3 in the "Announcement" matrix.
No idea how to insert text in a matrix (20X28 in this case) !
Many thanks in advance !
Pierre
1 个评论
采纳的回答
Geoff Hayes
2017-4-19
Pierre - since you are inserting strings of different lengths, your Announcements array will need to be come a cell array
Announcements = cell(N,28);
You will updates it simply as
Announcements{j,i} = 'good news';
etc.
Though you may want to keep your previous implementation and just manage an array of values between 1-3 and then (when you need to display your message) just access a map that converts the number to a string
mapIdToString = {'good news'; 'bad news' ; 'no news'};
The equivalent to the 1 (id) would then be
mapIdToString(1)
更多回答(1 个)
Andrei Bobrov
2017-4-19
D is Divident
F is Forecasted_DPS
A = {'good news','bad news','no news'};
ii = (D >= 1.03*F) + (D <= .97*F)*2;
ii(ii == 0) = 3;
Announcements = A(ii);
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!