% 删除字符串中所有的 16 进制的 0 char2asc2 = abs ( s ) ; % 转asc2 char2asc2 ( char2asc2 == 0 ) = [ ] ; % 删除NULL 0 s = char ( char2asc2 ) ; % 删除字符串中所有的 16 进制的 5 char2asc2 = abs ( s ) ; % 转asc2 char2asc2 ( char2asc2 == 5 ) = [ ] ; % 删除 5 s = char ( char2asc2 ) ; % 删除字符串中一个字符“H” char2asc2 = abs ( s ) ; % 转asc2 char2asc2 ( char2asc2 == abs ( 'H' ) ) = [ ] ; % 删除 5 s = char ( char2asc2 ) ;

2、MATLAB 一二三维矩阵之间转换

低维转高维
%一维转二维
A = 112
B2=reshape(A,[3,4])
% 一维转三维
B3=reshape(A,[2,2,3])
% 二维转三维
C3=reshape(B2,[2,2,3])
高维转低维
% 三维转二维
A=rand(3,3,3);
A1 = A(:,:,2); % 3*3 二维
A2 = A(:,2,:); % 3*1*3 三维
A3 = A(2,:,:); % 1*3*3 三维
% 将三维转为 81*81 二维
A22 = reshape(A2,3,3);
A32 = reshape(A3,3,3);
% 三维转一维
B1=reshape(A,1,[]);
% 二维转一维
C1=reshape(A22,1,[]);

3、MATLAB常见取整函数

函数	功能
round	四舍五入
fix	    保留整数部分
floor	向下取整
ceil	向上取整
sign	提取符号
rem	    取余数
mod	    取模数

4、MATLAB 将矩阵生成CSV文件

name=file_name;
various={'img','c0','c1','c2','c3','c4','c5','c6','c7','c8','c9'};
%表的内容
result_table=table(name,m1(:,1),m1(:,2),m1(:,3),m1(:,4),m1(:,5),m1(:,6),m1(:,7),m1(:,8),m1(:,9),m1(:,10),'VariableNames',various);
%创建csv表格
writetable(result_table, 'test.csv')
%----------------------------数据导入到csv------------------------
%all_data为你要保存的矩阵
result_table=table(all_data);
%创建csv表格
writetable(result_table, 'test.csv')

5、Matlab字符串连接加空格—strcat函数

matlab ASCII码32可以表示空格。

a1 = strcat('case ',32,num2str(count),':','{','D1=',num2str(b1),';','C1','=',num2str(b2),';','B1','=',num2str(b3),';','A1','=',num2str(b4),';}')
 

a1 = case 120:{D1=1;C1=1;B1=1;A1=0;}

6、将矩阵保存到txt

str = strcat('.\data_sample\','2', '.txt'); %数据保存路径
dlmwrite(str, data_sample);   %data_sample为矩阵

加载txt

load(str)

以下是matlab采集阻抗数据的部分代码

if mode == 0
    count = count + 1;
    data_sample = [data_sample;vi'];
    if count == num_sample_once
        dlmwrite(str, data_sample);
        fclose(s) 
                    Matlab常用操作1、MATLAB删除字符串中任意字符2、MATLAB 一二三维矩阵之间转换3、MATLAB常见取整函数1、MATLAB删除字符串中任意字符构建一个字符串:s% 删除空格  s(isspace(s)) = [];%去除空格%删除字符串中所有的16进制的0char2asc2=abs(s);%转asc2char2asc2(char2asc2==0)=[];%删除NULL 0s=char(char2asc2);%删除字符串中所有的16进制的5char2asc2=abs(s
我们有一个字符串file='20131030_113109.TemporaryAlias.Poly5';
简单操作举例:
>> a=file(7)    %取字符串任意一个元素
>> a=file(3:10)  %取字符串任意几个元素
131030_1
2 ‎建立一个字符串“I'm A STUDENT”,然后对该字符串做如下处理,写出MATLAB命令。
(1)将字符串的大写字母变成相应的小写字母,其余字符不变。
(2)将子字符串“student”替换为字符串“teacher”
				
大家想要删除字符数组或者字符串数组的首尾字符时首先想到的就是strtrim函数,但是这个函数有限制,就是其只能删除首尾的空白字符,而当我们想要删除其他特定字符时,就无能为力了。 例如如下代码,strtrim函数很好的删除了(连续)空白字符,但是不能删除特定字符,比如星号等等。 % Matlab stra = ' hello world '; strb = " hello world "; strc = " hello world *"; Fa = strtrim(stra);
<br />/*删除字符串数字并压缩字符串(神州数码以前笔试题), 如字符串"abc123de4fg56"处理后变为"abcdefg"。注意空间和效率*/ #include <cstdlib> #include <iostream> using namespace std; void hanStr(char *str) int len = strlen(str); int index = 0; for(int i=0; i<len; i++) 1. 定义一个新的字符串,长度为两个字符串长度之和加1(加1是为了留出字符串结尾的'\0')。 2. 使用循环将第一个字符串的每个字符依次复制到新字符串。 3. 再使用循环将第二个字符串的每个字符依次复制到新字符串。 4. 在新字符串的最后一个位置加上'\0',表示字符串的结尾。 5. 最后输出新字符串即可。 示例代码如下: #include <stdio.h> int main() char str1[100], str2[100], new_str[200]; int i, j; printf("请输入第一个字符串:"); scanf("%s", str1); printf("请输入第二个字符串:"); scanf("%s", str2); // 将第一个字符串复制到新字符串 for (i = 0; str1[i] != '\0'; i++) new_str[i] = str1[i]; // 将第二个字符串复制到新字符串 for (j = 0; str2[j] != '\0'; j++) new_str[i + j] = str2[j]; // 在新字符串的最后一个位置加上'\0' new_str[i + j] = '\0'; printf("连接后的字符串为:%s\n", new_str); return 0;