string matrix navigation with character string

13 views (last 30 days)
Hi; for my problem, I have a string matrix (DataSour) of size 3 in columns but strong in rows; for which I look to obtain a minimized matrix (DataFind) relative to a character string (ToAssign). Then I try to find the positions of the columns (ColPos) and rows (RowPos) where the character string is positioned.
DataSour = ["Do" "Ri" "Mi"; "AA" "VV" "Fa"; "SS" "BB" "Do"; "Do" "yy" "zz"]
ToAssign = "Do"
for results I have to find the minimized matrix
DataFind =
Do -- --
-- -- Do
Do -- --
and positions of columns
ColPos =
1
3
1
and positions of rows
RowPos =
1
3
4

Answers (2)

Matt J
Matt J on 17 Jun 2022
Edited: Matt J on 17 Jun 2022
DataSour = ["Do" "Ri" "Mi"; "AA" "VV" "Fa"; "SS" "BB" "Do"; "Do" "yy" "zz"];
ToAssign = "Do";
[ColPos,RowPos]=find(DataSour'==ToAssign)
ColPos = 3×1
1 3 1
RowPos = 3×1
1 3 4
  4 Comments
Matt J
Matt J on 19 Jun 2022
Edited: Matt J on 19 Jun 2022
You cannot use my solution unless you have a recent Matlab version. If you have upgraded, then convert DataSour to a string array, like in your posted example.

Sign in to comment.


Walter Roberson
Walter Roberson on 17 Jun 2022
[RowPos, ColPos] = find(ismember(DataSour, ToAssign))
  8 Comments
Walter Roberson
Walter Roberson on 23 Jun 2022
No, I mean
MYFile(cellfun(@(x) ~ischar(x), MYFile)) = {''};

Sign in to comment.

Products


Release

R2010b

Community Treasure Hunt

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

Start Hunting!