MATLAB Answers

Remove a line and column in a symbolic matrix and shift to -1 all the superior indices of names of variables into this symbolic matrix

3 views (last 30 days)
petit on 20 Jun 2021
Edited: petit on 20 Jun 2021
I have a 32x32 symbolic matrix
FISH_Big_18_SYM = sym('sp_', [32,32], 'positive');
After some computations on it, I would like to remove the 4th row/columns of this symbolic matrix. I tried :
FISH_Big_18_SYM(4,:) = [];
FISH_Big_18_SYM(:,4) = [];
I would like that all names variables should be decreased to 1 for all indices of variable names after 4, for example:
The last element sp_32_32 should become sp_31_31.
The element sp_10_7 should become sp_9_6.
How could I perform this?
ps : I don't want to remove the 32nd row and the 32nd column instead of the 4th
Any help/suggestion/track/clue is welcome
Best regards

Answers (2)

petit on 20 Jun 2021
Update :
For the moment with a 10x10 symbolic array, I tried (in a first decrease all the 2 indices from 1) :
regexprep(array_a,'a_\D_\D', 'a_eval(\D-1_\D-1)')
but indices are not decreased from 1 :
'[a_1_1, a_1_2, a_1_3, a_1_4, a_1_5, a_1_6, a_1_7, a_1_8, a_1_9, a_1_10; a_2_1, a_2_2, a_2_3, a_2_4, a_2_5, a_2_6, a_2_7, a_2_8, a_2_9, a_2_10; a_3_1, a_3_2, a_3_3, a_3_4, a_3_5, a_3_6, a_3_7, a_3_8, a_3_9, a_3_10; a_4_1, a_4_2, a_4_3, a_4_4, a_4_5, a_4_6, a_4_7, a_4_8, a_4_9, a_4_10; a_5_1, a_5_2, a_5_3, a_5_4, a_5_5, a_5_6, a_5_7, a_5_8, a_5_9, a_5_10; a_6_1, a_6_2, a_6_3, a_6_4, a_6_5, a_6_6, a_6_7, a_6_8, a_6_9, a_6_10; a_7_1, a_7_2, a_7_3, a_7_4, a_7_5, a_7_6, a_7_7, a_7_8, a_7_9, a_7_10; a_8_1, a_8_2, a_8_3, a_8_4, a_8_5, a_8_6, a_8_7, a_8_8, a_8_9, a_8_10; a_9_1, a_9_2, a_9_3, a_9_4, a_9_5, a_9_6, a_9_7, a_9_8, a_9_9, a_9_10; a_10_1, a_10_2, a_10_3, a_10_4, a_10_5, a_10_6, a_10_7, a_10_8, a_10_9, a_10_10]'
Remains also after this operation the inverse operation of char, i.e convert string to symbolic matrix array.
Does anybody see a solution ?

petit on 20 Jun 2021
**Update 1:**
For the moment with a 5x5 symbolic array, I managed to print pattern like this :
a =
[ a_1_1, a_1_2, a_1_3, a_1_4, a_1_5]
[ a_2_1, a_2_2, a_2_3, a_2_4, a_2_5]
[ a_3_1, a_3_2, a_3_3, a_3_4, a_3_5]
[ a_4_1, a_4_2, a_4_3, a_4_4, a_4_5]
[ a_5_1, a_5_2, a_5_3, a_5_4, a_5_5]
>> array_a=char(a)
array_a =
'[a_1_1, a_1_2, a_1_3, a_1_4, a_1_5; a_2_1, a_2_2, a_2_3, a_2_4, a_2_5; a_3_1, a_3_2, a_3_3, a_3_4, a_3_5; a_4_1, a_4_2, a_4_3, a_4_4, a_4_5; a_5_1, a_5_2, a_5_3, a_5_4, a_5_5]'
>> a=regexprep(array_a,'a_(\d*_\d*)','$1')
a =
'[1_1, 1_2, 1_3, 1_4, 1_5; 2_1, 2_2, 2_3, 2_4, 2_5; 3_1, 3_2, 3_3, 3_4, 3_5; 4_1, 4_2, 4_3, 4_4, 4_5; 5_1, 5_2, 5_3, 5_4, 5_5]'
Now, could I make decrease the indices from 1,for example starting from the 4th element of `a` ?
I think that I have to use `eval` but I don't know how ?
Remains also after this operation the inverse operation of `char`, i.e
convert string to symbolic matrix array.
I don't undertsand why the following doesn't work :
Error using regexprep
Evaluation of '$1-1' did not produce a char vector or scalar string.
Does anybody see a solution ?

Community Treasure Hunt

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

Start Hunting!