Generate new pairs based on a string

kgk

I have a string : str='HDEABGCF'. How can I create the new pairs which is from the second is combined with the third elements, the fourth with fifth , the sixth is combined with the seventh?

The expected output should be: result={'DE';'AB';'GC'}

rayryeng

You can abuse arrayfun, and ensuring you start from the second index of the string array going up to the second last index in increments of 2. For each index, you'd access the string at the current index and the next index after that point, then ensure that the output is a cell array by using the uni=0 flag:

>> str='HDEABGCF';
>> result = arrayfun(@(x) str([x x+1]), 2:2:numel(str)-1, 'uni', 0);
>> result

result = 

    'DE'    'AB'    'GC'

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

C# How to generate a new string based on multiple ranged index

From Dev

Generate cell pairs based on first row and column

From Dev

Generate new List<string> based on substring match in List<string> in c#

From Dev

Merge Sorting HashTable pairs based on String key

From Dev

Generate string based on regex with parameters

From Dev

R: Generate new columns based on nested loops

From Dev

Generate a new column based on data in multiple columns

From Dev

Split line into key-value pairs based on first string

From Dev

Generate String based on multiple values just inserted

From Dev

PHP: Generate dynamic sized image based on string

From Dev

CodeIgniter - generate a code based on a string that a user enters

From Dev

Generate array with pairs of numbers

From Dev

How to split a string into key-value pairs via new line dictionary<string,string>

From Dev

How to split a string into key-value pairs via new line dictionary<string,string>

From Dev

How to generate a string based on another given string's length?

From Dev

How to generate a new .xproj-based .NET Core project on Linux?

From Dev

JS: Compare two tables and generate new one based on the two

From Dev

Generate new worksheet based on column data for LARGE spreadsheets

From Dev

generate a new column based on values from another data frame

From Dev

Generate new rows in pandas by adding values based on previous rows

From Dev

Generate a new table using Java/SQL Based on values

From Dev

Generate a new column based on another column in the data matrix

From Dev

Generate new array based on array key type on ruby, rails

From Dev

Generate a new file based on a condition + column matching of two files

From Dev

Generate new column based on ratio of adjacent rows in pandas dataframe

From Dev

Python: Compare two lists with pairs and create a new list based upon membership and values

From Dev

Sorting array into array new based on string

From Dev

create a new column based on string of another column

From Dev

Sorting array into array new based on string

Related Related

  1. 1

    C# How to generate a new string based on multiple ranged index

  2. 2

    Generate cell pairs based on first row and column

  3. 3

    Generate new List<string> based on substring match in List<string> in c#

  4. 4

    Merge Sorting HashTable pairs based on String key

  5. 5

    Generate string based on regex with parameters

  6. 6

    R: Generate new columns based on nested loops

  7. 7

    Generate a new column based on data in multiple columns

  8. 8

    Split line into key-value pairs based on first string

  9. 9

    Generate String based on multiple values just inserted

  10. 10

    PHP: Generate dynamic sized image based on string

  11. 11

    CodeIgniter - generate a code based on a string that a user enters

  12. 12

    Generate array with pairs of numbers

  13. 13

    How to split a string into key-value pairs via new line dictionary<string,string>

  14. 14

    How to split a string into key-value pairs via new line dictionary<string,string>

  15. 15

    How to generate a string based on another given string's length?

  16. 16

    How to generate a new .xproj-based .NET Core project on Linux?

  17. 17

    JS: Compare two tables and generate new one based on the two

  18. 18

    Generate new worksheet based on column data for LARGE spreadsheets

  19. 19

    generate a new column based on values from another data frame

  20. 20

    Generate new rows in pandas by adding values based on previous rows

  21. 21

    Generate a new table using Java/SQL Based on values

  22. 22

    Generate a new column based on another column in the data matrix

  23. 23

    Generate new array based on array key type on ruby, rails

  24. 24

    Generate a new file based on a condition + column matching of two files

  25. 25

    Generate new column based on ratio of adjacent rows in pandas dataframe

  26. 26

    Python: Compare two lists with pairs and create a new list based upon membership and values

  27. 27

    Sorting array into array new based on string

  28. 28

    create a new column based on string of another column

  29. 29

    Sorting array into array new based on string

HotTag

Archive