在Matlab中对数据进行排序(Sorting Data in Matlab)

我试图在Matlab中对以下数据进行排序,但没有得到我需要的预期输出。

这是数据:

'1B-3A-5A'

'1A-3A-19A'

'2A-2A-4A-5A'

'2B-2A-5A'

'2A-4A-5A'

'2C-5A-30A'

'11A-3A-19A

'3A-19A-42C'

'4A-4A-12A'

'19A-21A-42C'

'25A-41D'

'41C-41C'

'39C-41C'

'43E'

'39A-41D'

'1A-3A-5A-7A'

'7C-27A-28A'

我需要排序列表,以便它考虑第一个数字,然后是字母表,对列表进行排序,如下所示

'1A-3A-19A'

'1A-3A-5A-7A'

'1B-3A-5A'

'2A-2A-4A-5A'

'2A-4A-5A'

'2B-2A-5A'

'2C-5A-30A'

'3A-19A-42C'

'4A-4A-12A'

'7C-27A-28A'

'11A-3A-19A

'19A-21A-42C'

'25A-41D'

'39A-41D'

'39C-41C'

'41C-41C'

'43E'

你能建议一个办法吗? 我尝试了所有方法,但它没有像我想要的那样排序。 谢谢!!

I am trying to sort the following data in the Matlab, but not getting the expected output what I need.

Here is data:

'1B-3A-5A'

'1A-3A-19A'

'2A-2A-4A-5A'

'2B-2A-5A'

'2A-4A-5A'

'2C-5A-30A'

'11A-3A-19A

'3A-19A-42C'

'4A-4A-12A'

'19A-21A-42C'

'25A-41D'

'41C-41C'

'39C-41C'

'43E'

'39A-41D'

'1A-3A-5A-7A'

'7C-27A-28A'

I need the sorted list such that it considers the first number then the alphabet to sort the list like below

'1A-3A-19A'

'1A-3A-5A-7A'

'1B-3A-5A'

'2A-2A-4A-5A'

'2A-4A-5A'

'2B-2A-5A'

'2C-5A-30A'

'3A-19A-42C'

'4A-4A-12A'

'7C-27A-28A'

'11A-3A-19A

'19A-21A-42C'

'25A-41D'

'39A-41D'

'39C-41C'

'41C-41C'

'43E'

Can you please suggest a way to do it? I tried all ways but it doesn't sort it like I want. Thanks!!

原文:https://stackoverflow.com/questions/32267557

更新时间:2020-01-31 15:08

最满意答案

如何使用sort或sortrows ? 这实际上也对字符串进行排序:

如果A是字符串,则sort(A)根据ASCII字典顺序排序。 排序区分大小写,大写字母出现在小写字母之前的输出中。

正如@StewieGriffin所指出的,这在11a之前对11a进行排序。 方便地,道格拉斯施瓦茨已经制作了一个代码 ,该代码首先克服了数字字母数字排序和数字字母排序问题。

How about using sort or sortrows? This does actually sort strings as well:

If A is a string, then sort(A) sorts according to the ASCII dictionary order. The sort is case sensitive with uppercase letters appearing in the output before the lowercase letters.

As @StewieGriffin pointed out, this sorts 11a before 1a. Conveniently Douglas Schwarz has already produced a code that overcomes exactly this problem of alphanumeric sorting on numerics first and characters after.

2015-08-28

相关问答

将数据A重塑为n行矩阵,其中n是平均大小,并应用mean来计算每列的平均值: A = [1 2 3 4]; %// data

n = 2; %// averaging size

P = mean(reshape(A,n,[]));

Reshape your data A into an n-row matrix, where n is the averaging size, and apply mean to compute the average of each column: A = [1

...

使用strmatch提取'正常'记录: normIdx = strmatch('normal.', Book2);

normalSubset = fulldata(normIdx, :);

然后为了生成250个随机非重复整数的列表,我搜索了“非重复随机整数的matlab列表”,并从第一个结果 : p = randperm(size(normalSubset , 1));

p = p(1:250)-1;

所以现在得到你的250个随机选择的正常记录 normalSample = normalSub

...

使用reshape和sort您可以: [~,idx]=sort(reshape(Audio_Version,4,[]));

idxtble = bsxfun(@plus,idx,0:4:(4*size(idx,2))-1);

table2 = table1(idxtble,:);

说明: 您可以提取音频列并将其重新整形为[4 * n]矩阵: audio = reshape(Audio_Version,4,[]);

然后对音频列进行排序并获取已排序元素的索引: [~,idx]=sort(aud

...

需要在execute方法中设置值: matlab.Execute(name + " = reshape (" + name + ",2,2)");

Need to set the value in the execute method: matlab.Execute(name + " = reshape (" + name + ",2,2)");

对,那是正确的。 更换 yfit1 = polyval(coef1,x);

同 yfit1 = polyval(coef1,(x-mu(1))/mu(2));

Yes, that is correct. Replace yfit1 = polyval(coef1,x);

with yfit1 = polyval(coef1,(x-mu(1))/mu(2));

如何使用sort或sortrows ? 这实际上也对字符串进行排序: 如果A是字符串,则sort(A)根据ASCII字典顺序排序。 排序区分大小写,大写字母出现在小写字母之前的输出中。 正如@StewieGriffin所指出的,这在11a之前对11a进行排序。 方便地,道格拉斯施瓦茨已经制作了一个代码 ,该代码首先克服了数字字母数字排序和数字字母排序问题。 How about using sort or sortrows? This does actually sort strings as we

...

假设all_data是一个单元格数组,并且每个单元格包含一个矩阵(至少有三列): result = cellfun(@(x) bsxfun(@rdivide, x, x(:,3)), all_data, 'uniformoutput', 0);

Assuming that all_data is a cell array and that each cell contains a matrix (with at least three columns): result = cellfun(@(x

...

答案没有假设 - 简化 我对旧的答案感到不自在,因为这个答案让所有东西都成为一个整数并消除了重复的可能性,所以我根据@ lib建议使用直方图和计数方法提出了不同的解决方案。 唯一可以看到这种情况不适用的情况是输入0。 你将得到一个全零的列,一个人可能会解释为最初包含零的所有行,但这将是不正确的。 在这种情况下你可以使用nan而不是zeros ,但是不确定这些数据是什么,以及它是否会处理这些数据。 EDITED 包括二级矩阵B的分类以及A. A = [-1 3 4 7 9; 0 2 2 7 8.2;

...

以这种方式使用unique和accumarray的组合 - [unique_ids,~,idmatch_indx] = unique(D(:,1));

%// unique_ids would have the unique numbers from first column and only

%// used to get the first column of final output, E.

%// idmatch_indx are tags put on each element c

...

matlab 日期排序_在Matlab中对数据进行排序(Sorting Data in Matlab)相关推荐

  1. arraylist怎么在mysql中排序_对ArrayList中对象元素进行排序

    rrayList中的元素进行排序,主要考查的是对util包中的Comparator接口和Collections类的使用. 实现Comparator接口必须实现compare方法,自己可以去看API帮助 ...

  2. react 数据库排序_如何使用React对表数据进行排序

    react 数据库排序 Often when you have a table with information you'd want to be able to sort the informati ...

  3. matlab excel 排序,“如何用matlab处理多个excel表格中的数据“excel怎么排序

    请问如何在matlab gui界面中插入excel表格并可进行编辑 最简单的方法,gui界面上一个table控件,放置两个按钮. 按钮名字分别改为打开和保存,table的属性里,把columnname ...

  4. 利用matlab处理表格数据,/如何用matlab处理多个excel表格中的数据

    excel最大可处理多少条数据 理论上可以处理59999条(行)数据 但是实际上同一个工作表中无法处理这么多数. Excel 怎样做一个客户多个数据的表 1.首先,简单描述问题,在如下的表格中想姓名一 ...

  5. mysql 如何对表排序_学习MySQL:对表中的数据进行排序和过滤

    mysql 如何对表排序 In this article, we will learn how we can sort and filter data using the WHERE clause a ...

  6. 用matlab处理表格,matlab删除excel表格数据-如何用matlab处理多个excel表格中的数据...

    如何用matlab处理多个excel表格中的数据 biao='D:\Program Files\matlab\bin\filename.xls'; A1=xlsread (biao,'Sheet1', ...

  7. C# 对Excel表格中的数据进行排序

    使用Excel处理数据时我们经常需要用到数据排序功能,这篇文章将介绍如何使用C#对Excel中的数据进行排序.这里介绍三种排序方式: 基于单元格的值进行排序 基于单元格的背景颜色进行排序 基于单元格的 ...

  8. 对数据库中的数据进行排序

    ** 对数据库中的数据进行排序 ** 使用SELECT语句从表中查询数据时,不保证结果集中的行顺序.这意味着SQL Server可以返回具有未指定顺序的结果集. 保证结果集中的行已排序的方法是使用OR ...

  9. matlab 平滑曲线连接_【仪光学习】技能分享 | 前方高能:如何用Matlab轻松实现数学建模...

    作为前阵子被禁用的Matlab到底有怎样的魔力呢?Matlab毫无疑问是理工生的科研神器,在各大建模比赛中也被高频使用,下面就来聊聊Matlab的一些"奇技淫巧". 一 基础用法 ...

最新文章

  1. 解决bootstrap下的图片自适应问题
  2. 快讯 | 首期“医工结合系列研讨会”汇聚清华力量,共促医工融合发展
  3. XPath 详解,总结
  4. php学习之try catch
  5. 如何成为有思想、创新的程序员
  6. oracle归档日志保留时间,Oracle 11g Data Guard 备库归档日志清理脚本(保留一周归档)...
  7. ubuntu系统备份和还原_如何使用Aptik在Ubuntu中备份和还原您的应用程序和PPA
  8. mysql中join各种形式大全及操作和图片
  9. 给定一个正整数,计算有多少对质数的和等于输入的这个正整数
  10. 三实系统地址是什么意思_终于明白!火灾报警系统的余量应该如何设置?地址数又是什么?...
  11. 百度文库下载文档,没财富值,没下载卷也能下载
  12. CSDN首页 云计算 孙玄:解析58同城典型技术架构及演变
  13. High-Dimensional Statistics A Non-Asymptotic Viewpoint by Martin J. Wainwright Exercise7.3
  14. 调频去加重 matlab,调频广播中预加重和去加重问题的讨论.doc
  15. 神经网络训练结果都是1,神经网络训练效果不好
  16. 网卡TSO、UFO、GSO、LRO、GRO和RSS介绍
  17. 笔记本电脑如何锁定计算机,笔记本电脑怎么锁定关闭触摸板
  18. iOS开发:下架App的步骤
  19. 逮到一个阿里 10 年老 测试开发,聊过之后收益良多...
  20. Nginx反向代理配置详解

热门文章

  1. 通过CSS,H5,JavaScript实现表格表单的随机选择,和简单的随机点名。
  2. 给c语言程序更换图标
  3. ‘EddiesObservations‘ object has no attribute ‘filled‘
  4. STK二次开发之MATLAB 初始化
  5. FMEA软件——企业为什么要开发FMEA?
  6. Windows权限提升—溢出提权
  7. OpenLayers入门(二)
  8. 中国中小企业年鉴(1996-2018)缺2017、1998-2002
  9. uni-app mescroll-body的用法
  10. 封装echart圆饼图