Asking for help with variables

조회 수: 2 (최근 30일)
Ivan
Ivan 2024년 9월 15일
댓글: Ivan 2024년 9월 16일
1) I am developing a code and I have stored a column from a database (numerical values) inside a variable. When using the 'ones' function and utilizing the variable where I have stored the column, the code does not work. However, when I program the same function and call the column of values directly, it allows me to run the code. Is there any way to use the name of the variable that I created?
n_inter = length(data_inter.RSN); % Utilizado para regresion
n_intra = length(data_intra.RSN); % Utilizado para regresion
x_axis = PGA1100_inter; % variable seleccionada para eje x
X_inter = [ones(n_inter,1) data_inter.PGA1100]; %(allows me)
X_intra = [ones(n_intra,1) x_axis]; %(does not allow)
2) Also, I would like to know if it is possible to store the following code inside a table, meaning that the workspace looks much cleaner and all the generated variables are stored inside a table.
% Interplaca
[b_inter_PGA] = regress(data_inter.res_PGA, X_inter);
[b_inter_PGV] = regress(data_inter.res_PGV, X_inter);
[b_inter_002] = regress(data_inter.res_002, X_inter);
[b_inter_015] = regress(data_inter.res_015, X_inter);
[b_inter_02] = regress(data_inter.res_02, X_inter);
[b_inter_03] = regress(data_inter.res_03, X_inter);
[b_inter_1] = regress(data_inter.res_1, X_inter);
[b_inter_3] = regress(data_inter.res_3, X_inter);
  댓글 수: 1
Walter Roberson
Walter Roberson 2024년 9월 16일
We can speculate that:
  • perhaps length(data_inter.PGA1100) is not the same as length(PGA1100_inter)
  • perhaps PGA1100_inter is a row vector but data_inter.PGA1100 is a column vector
  • perhaps PGA1100_inter is a column vector but data_inter.PGA1100 is a row vector

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2024년 9월 16일
% Interplaca
T = table();
T.b_inter_PGA = regress(data_inter.res_PGA, X_inter);
T.b_inter_PGV = regress(data_inter.res_PGV, X_inter);
T.b_inter_002 = regress(data_inter.res_002, X_inter);
T.b_inter_015 = regress(data_inter.res_015, X_inter);
T.b_inter_02 = regress(data_inter.res_02, X_inter);
T.b_inter_03 = regress(data_inter.res_03, X_inter);
T.b_inter_1 = regress(data_inter.res_1, X_inter);
T.b_inter_3 = regress(data_inter.res_3, X_inter);
  댓글 수: 1
Ivan
Ivan 2024년 9월 16일
Thanks a lot, it worked

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Database Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by