How to Swap Column according to odd/even numbers?

3 ビュー (過去 30 日間)
hanif hamden
hanif hamden 2020 年 11 月 24 日
コメント済み: hanif hamden 2020 年 11 月 24 日
Hi everyone, I would like to arrange my column according to odd and even numbers. Example data is shown below, I want to arrange column 1(even numbers) while column2 (odd numbers). Can anyone help me on how to arrange / swap into the according column.
nPASS1 nPASS166
nPASS1 nPASS64
nPASS101 nPASS12
nPASS101 nPASS88
nPASS103 nPASS166
nPASS103 nPASS90
nPASS114 nPASS229
nPASS114 nPASS51
nPASS12 nPASS127
  4 件のコメント
James Tursa
James Tursa 2020 年 11 月 24 日
How is this stored? Cell array of char strings? Array of strings? Or ...???
hanif hamden
hanif hamden 2020 年 11 月 24 日
This is how I read the data from textfile. I attached the file as well
clc; clear all;close all;
filename = 'XOpairs.txt';
fileID = fopen(filename);
C = textscan(fileID,'%s %s ');
fclose(fileID);

サインインしてコメントする。

回答 (1 件)

KSSV
KSSV 2020 年 11 月 24 日
This is basic in MATLAB. You should read about indexing an array.
Example:
A = rand (10.1); % array for demo
E = A (2: 2: end); % get even indices number
O = A (1: 2: end); % GEt odd indices numbersY
You may also have cell arrays. For cell arrays you need to use {} for indexing.
  2 件のコメント
James Tursa
James Tursa 2020 年 11 月 24 日
This is not what OP asked.
KSSV
KSSV 2020 年 11 月 24 日
Let it be. If he is not satisfied, he will ask the question again. There is no harm right?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by