我正在尝试将一些数据输出到.csv文件,并将其输出到文件,但它没有将数据分成不同的列,似乎输出数据不正确.
ofstream Morison_File ("linear_wave_loading.csv"); //Opening file to print info to
Morison_File << "Time Force(N/m)" << endl; //Headings for file
for (t = 0; t <= 20; t++) {
u = sin(omega * t);
du = cos(omega * t);
F = (0.5 * rho * C_d * D * u * fabs(u)) + rho * Area * C_m * du;
cout << "t = " << t << "\t\tF = " << F << endl;
Morison_File << t; //Printing to file …Run Code Online (Sandbox Code Playgroud) 我有一个用C++编写的代码,它输出一个.csv文件,其中包含三列数据(时间,力,高度).我想使用Octave绘制数据,或者使用C++文件中的八度函数图(我知道这是可能的,但我不一定需要这样做).
现在我有简单的.m文件:
filename = linear_wave_loading.csv;
M = csvread(filename);
Run Code Online (Sandbox Code Playgroud)
只是为了练习将这个文件变为八度(将尝试并绘制后)我收到此错误.
error: dlmread: error parsing range
Run Code Online (Sandbox Code Playgroud)
将.csv文件加载到八度音程的正确方法是什么?
编辑:这是我的.csv文件的前几行
Wavelength= 88.7927 m
Time Height Force(KN/m)
0 -20 70668.2
0 -19 65875
0 -18 61411.9
0 -17 57256.4
Run Code Online (Sandbox Code Playgroud)
在此先感谢您的帮助.
我只是有一个简单的问题,因为我试图了解如何在 C++ 中编译(在 ubuntu 12.04 中)包含一个简单头文件的 main 。
命令:
g++ -o main main.cpp add.cpp -Wall
Run Code Online (Sandbox Code Playgroud)
工作正常。然而,这让我对头文件的意义感到困惑。目前,我有一个简单的程序:
#include <iostream>
#include "add.h"
using namespace std;
int main () {
int a, b;
cout << "Enter two numbers to add together" << endl;
cin >> a >> b;
cout << "Sum of " << a << " and " << b << " is " << add(a,b) << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我的“add.cpp”只是将两个数字加在一起。
头文件只是函数原型的替换吗?我是否需要单独编译头文件,或者在命令行中包含所有 .cpp 文件就足够了吗?我知道如果我需要更多文件,则需要生成文件。
我正在使用 Octave 编写一个脚本来绘制不同时间段的函数。我希望制作一个情节动画,以便看到随时间的变化。
有没有办法保存每个时间点的每个图,以便可以组合所有图来创建此动画?
这是我第一天搞乱C++.我正在尝试做一个非常基本的代码,寻找二次方程中的根.到目前为止,这是我的代码:
#include <iostream>
#include <cmath>
int main () {
int a, b, c;
double root1, root2;
std::cout << "Enter the integers a, b, and c to fit in the quadratic equation: ax^2 + bx + c >> " << std::endl;
std::cout << "a = ";
std::cin >> a;
std::cout << "b = ";
std::cin >> b;
std::cout << "c = ";
std::cin >> c;
std::cout <<"\n";
std::cout << "Quadratic equation to solve is : " << a << "x^2 + …Run Code Online (Sandbox Code Playgroud) 有一个非常简单的代码,我用C++构建.这是我的第一个C++代码,所以我不完全确定某些地方的语法.但是,对于以下代码,我的for循环根本没有运行!我不明白为什么不...有人能发现问题吗?
#include <cstdlib>
#include <cmath>
using namespace std;
int main () {
/*
* Use values for wavelength (L) and wave number (k) calculated from linear
* dispersion program
*
*/
//Values to calculate
double u; //Wave velocity: d*phi/dx
double du; //Acceleration of wave: du/dt
int t;
//Temporary values for kn and L (taken from linear dispersion solution)
float L = 88.7927;
float kn = 0.0707624;
Run Code Online (Sandbox Code Playgroud)
注意:我省略了变量声明以节省空间.
/*
* Velocity potential = phi = ((Area * g)/omega) * ((cosh(kn * …Run Code Online (Sandbox Code Playgroud)