小编Jac*_*ses的帖子

将matlab矩阵分成几个相等的部分

我有一个大小的矩阵64500x17.它代表检测到的texton功能,我必须用它来找到5个质心kmeans.

我需要的是:

  • 将该矩阵分成5个12900x17矩阵
  • 找到手段
  • 将它们连接成一个5x17矩阵,以输入到的start参数kmeans.

我知道该怎么做几乎所有的东西(cat,kmeans,等),但我只是想找到一个矩阵分成5个部分,或加/划分成所需大小的方法.

除非绝对必要,否则我禁止过度使用循环(由于效率).

我在其他问题中找不到任何相关的例子,所以如果这个问题得到了回答,请耐心等待.

matlab matrix k-means

7
推荐指数
2
解决办法
8761
查看次数

从文本文件初始化矢量

我正在尝试编写一个可以读入文本文件的程序,并将其中的每个单词存储为字符串类型向量中的条目.我确信我这样做是非常错误的,但是自从我试图做到这一点以来,我已经忘记了它是如何完成的.任何帮助是极大的赞赏.提前致谢.

码:

#include <iostream>
#include <fstream>
#include <vector>
#include <string>

using namespace std;

int main()
{
    vector<string> input;
    ifstream readFile;

    vector<string>::iterator it;
    it = input.begin();

    readFile.open("input.txt");

    for (it; ; it++)
    {
        char cWord[20];
        string word;

        word = readFile.get(*cWord, 20, '\n');

        if (!readFile.eof())
        {
            input.push_back(word);
        }
        else
            break;
    }

    cout << "Vector Size is now %d" << input.size();

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ string file-io vector formatted-input

2
推荐指数
1
解决办法
9219
查看次数

多个POSIX线程

我有一个家庭作业问题,我目前仍然坚持.问题的参数如下.1.)它必须接受来自用户的总共5个整数.

2.)它必须有三个线程,每个线程执行不同的功能(平均值,最小值和最大值).

我遇到的问题是声明一个包含5个元素的全局数组空数组,然后修改这些元素.每次我最终得到一个段错误,告诉我我做错了.顺便说一句,语言是C,重点不是C++(我不允许使用它).如果有人能帮我理解什么是错的,我将不胜感激.此外,如果它是重复的(我看,我看到没有解决这些问题),请指出我的问题或文章,它的地址谢谢.

码:

#include <stdio.h>
#include <pthread.h>

void *avgWorker(int in[]);
void *minWorker(int in[]);
void *maxWorker(int in[]);

int main(void)
{
  int it, *input;

  int in[5];

  pthread_t tid1,tid2,tid3;
  pthread_attr_t attr1, attr2,attr3;

  for (it = 0; it < 5; ++it)
    {
      printf("Please enter number %d of 5\n", (it + 1));

      input[it] = scanf("%d");
    }

  pthread_attr_init(&attr1);
  pthread_attr_init(&attr2);
  pthread_attr_init(&attr3);

  pthread_create(&tid1, &attr1, avgWorker(in), NULL);
  pthread_create(&tid2, &attr2, minWorker(in), NULL);
  pthread_create(&tid3, &attr3, maxWorker(in), NULL);

  pthread_join(tid1,NULL);
  pthread_join(tid2,NULL);
  pthread_join(tid3,NULL);

  return 0;
}

void *avgWorker(int in[])
{
  int total, avg, …
Run Code Online (Sandbox Code Playgroud)

c multithreading pthreads

0
推荐指数
1
解决办法
351
查看次数

用于在C++中将信息写入文件的函数

我一直在为学校做项目,我遇到了一个问题.我试图避免在程序中对所有内容进行硬编码,而我的部分要求是使用fstream.这是抛出错误的原因.我使用G ++作为我的编译器.

void order::printToFile(string file)
{
ofstream output;

try
{
    output.open(file, ios::app);
}

catch(...)
{
    cerr << "An error has occurred";
}

output << this->info.orderID << setw(10) << this->info.type << setw(10) << this->info.quantity << setw(10) << this->info.zip << setw(10) << (this->info.shipCost + this->info.wholesale) << setw(10) << this->info.profit << endl << endl;

output.close();

}
Run Code Online (Sandbox Code Playgroud)

它给了我以下错误:

没有匹配的功能要求 'std::basic ofstream<char>::open( std::string&, const openmode&)'

有人可以帮我一把吗?谢谢

c++ fstream ofstream c++11

0
推荐指数
1
解决办法
2179
查看次数