Symbol in a numeric array

11 visualizzazioni (ultimi 30 giorni)
MdRezwan Parvez
MdRezwan Parvez il 19 Dic 2019
Risposto: Samatha Aleti il 24 Dic 2019
Hi,
one of the variable is appearing in the following way:
but I want to put '|' sign instead of 45 in the numerical matrix so that it will show only | instead of 45. I wrote the following code but '|' symbol is appearing as 45 in the numerical array.
---------------------------------------------------
seq1_gap_idx = find(tb=='L');
logical_idx = false(1,length(hsp_u{f_ind1}.seq1(:,1))+length(seq1_gap_idx));
logical_idx(seq1_gap_idx) = true;
new_seq1 = nan(size(logical_idx));
new_seq1(~logical_idx) = hsp_u{f_ind1}.seq1(:,1)';
% new_seq1 = char(new_seq1(logical_idx));
% new_seq1=str(new_seq1)
new_seq1(logical_idx) ='|';
---------------------------------------------------
I will appreciate your help. Thanks

Risposte (1)

Samatha Aleti
Samatha Aleti il 24 Dic 2019
Numeric arrays can never contain strings or characters. It takes the ASCII value of that character if you try to replace an element in numerical matrix with a char”. You can use cell arrays to do this. As an example, refer the following code:
new_seq1 = [45 16 20 42]; % let
new_cell = num2cell(new_seq1); % save numerical array in cell format
new_cell {1} = 'I'; % replace
Refer the following document for more details on Cell Arrays:

Categorie

Scopri di più su Creating, Deleting, and Querying Graphics Objects in Help Center e File Exchange

Prodotti


Release

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by