zoukankan      html  css  js  c++  java
  • String数据转Matrix矩阵

    String数据转Matrix矩阵

    private Matrix String_To_Matrix(string str)

    {

                int[] Remove_Num = new int[10];

                int Remove_Int = 0;

                string Str_One = str;

                //{ {M11:1 M12:0 M13:0 M14:0} {M21:0 M22:1 M23:0 M24:0} {M31:0 M32:0 M33:1 M34:0} {M41:0 M42:0 M43:0 M44:1} }

                //string Str_One = "{ {M11:1 M12:0 M13:0 M14:0} {M21:0 M22:1 M23:0 M24:0} {M31:0 M32:0 M33:1 M34:0} {M41:0 M42:0 M43:0 M44:1} }";

                for (int i = 0; i < Str_One.Length; i++)

                {

                    //string str = Str_One[i].ToString ();

                    if (Str_One[i].Equals('{') || Str_One[i].Equals('}'))

                    {

                        Remove_Num[Remove_Int] = i;

                        Remove_Int += 1;

                    }

                }

                Remove_Int = 0;

                int Remove_num_int = 0;

                string Str_Two = "";// M11:1 M12:0 M13:0 M14:0 M21:0 M22:1 M23:0 M24:0 M31:0 M32:0 M33:1 M34:0 M41:0 M42:0 M43:0 M44:1

                foreach (var item in Remove_Num)

                {

                    //string str = item.ToString();

                    Remove_num_int = item - Remove_Int;

                    Str_Two = Str_One.Remove(Remove_num_int, 1);

                    Str_One = Str_Two;

                    Remove_Int += 1;

                }

                string[] M_int = new string[16];// 1 0 0 0 ,0 1 0 0 ,0 0 1 0 ,0 0 0 1

                for (int i = 0; i < 16; i++)

                {

                    M_int[i] = (Str_Two.Split(' ')[i + 1]).Split(':')[1];

                }

                //Matrix aaaa = new Matrix(0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1);

                Matrix new_Matrix = new Matrix(float.Parse(M_int[0]), float.Parse(M_int[1]), float.Parse(M_int[2]), float.Parse(M_int[3]), float.Parse(M_int[4]), float.Parse(M_int[5]), float.Parse(M_int[6]), float.Parse(M_int[7]), float.Parse(M_int[8]), float.Parse(M_int[9]), float.Parse(M_int[10]), float.Parse(M_int[11]), float.Parse(M_int[12]), float.Parse(M_int[13]), float.Parse(M_int[14]), float.Parse(M_int[15]));

                return new_Matrix;

    }

    注:取Matrix格式string字符串,循环判断添加索引int[]数组,去除‘{}',再根据’  ‘进行对整体string分割取string[],之后依据':'分割读取float于float[]数组,对新建Matrix依次赋值,达到string转matrix效果.....

    支持个人观看使用,如商用或转载,请告知! -----萧朗(QQ:453929789 Email:xiaolang_xl@sina.com)
  • 相关阅读:
    A Simple Problem About Truth Table
    Android Fragment完全解析,关于碎片你所需知道的一切
    Android系统中标准Intent的使用
    Android应用开发全程实录-你有多熟悉listView
    Android四大基本组件介绍及生命周期
    设计模式
    Java流(Stream)、文件(File)和IO
    Java网络编程详解
    Java 多线程
    深入理解Java虚拟机 精华总结(面试)
  • 原文地址:https://www.cnblogs.com/XiaoLang0/p/10214056.html
Copyright © 2011-2022 走看看