Create new column based on values of other columns

25 ビュー (過去 30 日間)
Joe Opdenaker
Joe Opdenaker 2022 年 10 月 17 日
回答済み: Vinayak 2023 年 5 月 23 日
I need to create a new variable column based on values of other variables.
I need to do this for multiple subjects (n=35). Also multiple blocks (8).
I have a matrix of trials, blocks, IV1, IV2, IV3, DV
  1 件のコメント
Ghazwan
Ghazwan 2022 年 10 月 17 日
You need to write the code and post it here.

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

回答 (1 件)

Vinayak
Vinayak 2023 年 5 月 23 日
Hi Joe,
I am not sure regarding the condition on the basis of which you want to create the new column based off the other columns.
Assuming, you want to create a new column say IV7 (7th column), which is a sum of IV1, IV2 and IV3, (1st 3 columns), you can use the following code snippet.
% Load your data into a matrix called 'data'
load('data.mat')
% Create a new column based on the values of IV1, IV2, and IV3
data(:,7) = data(:,3) + data(:,4) + data(:,5);
% Save the updated matrix to a new file
save('updated_data.mat', 'data')
Thanks,
Vinayak

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by