Create matrices from strings in a cell-array

kgk

I have a string S1='ACD'. I generate the matrix based on the S1 as follows:

fullSeq = 'ABCD';
idx = find(fullSeq == setdiff(fullSeq, 'ACD')); % it is OK 
M(:,idx) = 0.5
M(idx,:) = 0.5
M(logical(eye(4))) = 0.5

The output is OK:

M =

0.5000    0.5000    0.2003    0.3279
0.5000    0.5000    0.5000    0.5000
0.8298    0.5000    0.5000    0.2452
0.7997    0.5000    0.7548    0.5000

Now, I would like to use a loop though the cell-array input-cell to generate 3 matrices (based on the above code) of the 3 strings in the cell-array as follows:

input_cell= {'ABCD','ACD', 'ABD'}


for i=1:numel(input_cell)



    M = 0.5*rand(4) + 0.5;

    M(triu(true(4))) = 1 - M(tril(true(4)));   

    fullSeq = 'ABCD';
    idx = find(fullSeq == setdiff(fullSeq, input_cell{i} )); % something wrong here

     M(:,idx) = 0.5
     M(idx,:) = 0.5
     M(logical(eye(4))) = 0.5

end

The error is :

 Error using  == Matrix dimensions must agree.

 Error in datagenerator (line 22)
 idx = find(fullSeq == setdiff(fullSeq, input_cell{i} ));   

How can I fix this problem to generate 3 matrices? Or any other solutions instead of using "for loop" ?

Dan

Try changing

fullSeq = 'ABCD';
idx = find(fullSeq == setdiff(fullSeq, input_cell{i} )); % something wrong here
...

to this:

fullSeq = 'ABCD';
letter = setdiff(fullSeq, input_cell{i})
if isempty(letter)
    idx = find(fullSeq == letter);
    M(:,idx) = 0.5
    M(idx,:) = 0.5
end
M(logical(eye(4))) = 0.5

But also, you realise that you are just overwriting M at each iteration and never actually storing the past results right?

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Converting cell array of strings with number arrays to matrices

From Dev

Removing duplicate strings from a nested cell array

From Dev

Stacking matrices from a cell array on top of one another (MATLAB)

From Dev

Cell array (or matrices) of matries in R

From Dev

create array of object from array of strings

From Dev

Create array of strings from array of documents in MongoDB

From Dev

Numpy create an array of matrices

From Dev

How to create a sub-cell from a cell array in Matlab?

From Dev

Create an array of matrices from 1D arrays in python

From Dev

How can I create a cell array in matlab combining text and number matrices?

From Dev

How to create an array of characters from a hashset of strings?

From Dev

Javascript: Create dictionary from array of strings

From Java

How to create an InputStream from an array of strings

From Dev

Swift - Create list of strings from two array

From Dev

Create simple array of strings from object

From Dev

Create a larger string from an array of strings

From Dev

How to create a dataframe from Array[Strings]?

From Dev

Create Array of Strings from Group Contents

From Dev

create arrays from array containg specific strings

From Dev

Create comma separated strings from multidimensional array

From Dev

Create array of strings from an input string

From Dev

Create type property from an array of strings

From Dev

calculate mean from cell array with mixed numbers and strings

From Dev

Removing 'NaN' strings and [] cells from cell array in Matlab

From Dev

Convert cell array to array of strings

From Dev

Find strings of a cell array in another cell array

From Dev

Create new matrices from the comparison of two matrices

From Dev

Conversion from 3D cell array to a set of 2D matrices

From Dev

How do I remove a certain column from matrices in a cell array in MATLAB?

Related Related

  1. 1

    Converting cell array of strings with number arrays to matrices

  2. 2

    Removing duplicate strings from a nested cell array

  3. 3

    Stacking matrices from a cell array on top of one another (MATLAB)

  4. 4

    Cell array (or matrices) of matries in R

  5. 5

    create array of object from array of strings

  6. 6

    Create array of strings from array of documents in MongoDB

  7. 7

    Numpy create an array of matrices

  8. 8

    How to create a sub-cell from a cell array in Matlab?

  9. 9

    Create an array of matrices from 1D arrays in python

  10. 10

    How can I create a cell array in matlab combining text and number matrices?

  11. 11

    How to create an array of characters from a hashset of strings?

  12. 12

    Javascript: Create dictionary from array of strings

  13. 13

    How to create an InputStream from an array of strings

  14. 14

    Swift - Create list of strings from two array

  15. 15

    Create simple array of strings from object

  16. 16

    Create a larger string from an array of strings

  17. 17

    How to create a dataframe from Array[Strings]?

  18. 18

    Create Array of Strings from Group Contents

  19. 19

    create arrays from array containg specific strings

  20. 20

    Create comma separated strings from multidimensional array

  21. 21

    Create array of strings from an input string

  22. 22

    Create type property from an array of strings

  23. 23

    calculate mean from cell array with mixed numbers and strings

  24. 24

    Removing 'NaN' strings and [] cells from cell array in Matlab

  25. 25

    Convert cell array to array of strings

  26. 26

    Find strings of a cell array in another cell array

  27. 27

    Create new matrices from the comparison of two matrices

  28. 28

    Conversion from 3D cell array to a set of 2D matrices

  29. 29

    How do I remove a certain column from matrices in a cell array in MATLAB?

HotTag

Archive