Midpoint between 2 numbers in 2 columns in the same csv file

5 ビュー (過去 30 日間)
Tom
Tom 2022 年 12 月 12 日
コメント済み: Jon 2022 年 12 月 12 日
I'm working on a project where i need to find the midpoint between a minimum and maximum value to then plot a curve. i haver very limited experience in matlab and currently am having to use excel to calculate the midpoint between the 2 numbers as they are exported from software as 2 seperate csv files.
is there a way to either:
a) write the script to automatically find the midpoint between 2 numbers from 2 seperate csv files (they are the y-axis on a graph and the x-axis intervals stay the same)
or
b) the same as above but from 1 csv file?
obviously finding the point from the 2 seperate files will be easier but if needs be i can combine the 2, 2 column files in 1, 3 column file before improting to matlab.
any help would be greatly appreciated, as i said above this is slightly outside my knowledge of matlab, i am happy to provide an example of the csv files and what ive got my script to run so far

採用された回答

Jon
Jon 2022 年 12 月 12 日
編集済み: Jon 2022 年 12 月 12 日
% read in the data
dat1 = readmatrix("File1.csv");
dat2 = readmatrix("File2.csv");
% assume first column matches, and compute midpoints
mid = mean([dat1(:,2),dat2(:,2)],2) % compute mean of each row
mid = 4×1
15 25 35 45
  2 件のコメント
Image Analyst
Image Analyst 2022 年 12 月 12 日
Then
plot(dat1, 'r.-', 'LineWidth', 2);
grid on;
hold on;
plot(dat2, 'b.-', 'LineWidth', 2);
plot(mid, 'g.-', 'LineWidth', 2);
@Tom To learn other fundamental concepts, invest 2 hours of your time here:
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
Jon
Jon 2022 年 12 月 12 日
@Image Analyst - thank you for the follow up regarding the OP's question about plotting, and the training suggestions. One small correction, since dat1 and dat2 also include the first column from the file, I think the plotting commands should be
plot(dat1(:,2), 'r.-', 'LineWidth', 2);
grid on;
hold on;
plot(dat2(:,2), 'b.-', 'LineWidth', 2);
plot(mid, 'g.-', 'LineWidth', 2);
or we could put all three curves into one array, and assuming the x axis is the same for all just grab it from one of the data arrays.
x = dat1(:,1);
Y = [dat1(:,2),dat2(:,2),mid];
plot(x,Y)
legend('File1','File2','Midpoint','Location','best')

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by