How to get value from this type of table?

2 visualizaciones (últimos 30 días)
Muhammad Imran
Muhammad Imran el 18 de Abr. de 2020
Comentada: Muhammad Imran el 24 de Abr. de 2020
Hi. I want to create a code which can take extract a value of Cv coeffiecient from excel table given below, if user gives the value of Z and Soil Profile type as a string i.e Sa?
For now, i can omit Sf soil profile type.
Kind Regards,
Imran
  5 comentarios
Muhammad Imran
Muhammad Imran el 18 de Abr. de 2020
Some has similar formatting and some are like one vs one relation. You give one value and extract the other value against it from excel table.
Muhammad Imran
Muhammad Imran el 18 de Abr. de 2020
And plus how can i recreate to make it easier to read? Can you give me an example with simpler matlab code.?

Iniciar sesión para comentar.

Respuestas (2)

Cris LaPierre
Cris LaPierre el 18 de Abr. de 2020
Unless you have a lot of these to read in, it's going to be quicker to either
  1. recreate this table in a format that is easier to read in, or
  2. create a script that defines variables for each value.
SA_Z075 = 0.06;
SB_Z075 = 0.08;
...
SE_Z4 = 0.96;
You could either run this script at the top of any other script that needs these values, or run it once and save the variables to a mat file, then load that mat file when you need them.
  2 comentarios
Muhammad Imran
Muhammad Imran el 18 de Abr. de 2020
Dear, I have a lot of tables like these and i have to add them to get values and do some calculations at the end. It will be easier to use tables i guess.
Cris LaPierre
Cris LaPierre el 18 de Abr. de 2020
Editada: Cris LaPierre el 18 de Abr. de 2020
The best way to try importing data is to use the Import Tool. This allows you to interactively adjust the import settings. When you have what you want, you can then generate code that you can then add to your own code.
I'm a little more comfortable coding things up myself, so I'd probably do something like this
filename = "Table 16-R.xlsx";
opts = detectImportOptions(filename,'ReadRowNames',true);
opts.VariableNames = ["Z0075", "Z015", "Z02", "Z03", "Z04"];
zTbl = readtable(filename,opts)
As a table with Soil Profile Type as the row name, I can then index the table use the Soil Profile Type and Seismic Zone Factor. Notice I am using curly braces to access the table value.
Z=zTbl{"SA","Z015"}
Here, the result is Z = 0.1200

Iniciar sesión para comentar.


Image Analyst
Image Analyst el 18 de Abr. de 2020
Try this. It works for all 5 cases, plus even works if the z is not one of the columns exactly.
fileName = fullfile(pwd, 'Table 16-R.xlsx');
[numbers, strings, raw] = xlsread(fileName)
lookUpTable = [0.075, .15, .2, .3, .4];
zInput = 0.075;
% Find the column that is closest to what the user input for Z:
[~, closestColumn] = min(abs(zInput - lookUpTable))
% Extract the SA for that column:
SA = numbers(1, closestColumn)
zInput = 0.15;
% Find the column that is closest to what the user input for Z:
[~, closestColumn] = min(abs(zInput - lookUpTable))
% Extract the SA for that column:
SA = numbers(1, closestColumn)
zInput = 0.2;
% Find the column that is closest to what the user input for Z:
[~, closestColumn] = min(abs(zInput - lookUpTable))
% Extract the SA for that column:
SA = numbers(1, closestColumn)
zInput = 0.3;
% Find the column that is closest to what the user input for Z:
[~, closestColumn] = min(abs(zInput - lookUpTable))
% Extract the SA for that column:
SA = numbers(1, closestColumn)
zInput = 0.4;
% Find the column that is closest to what the user input for Z:
[~, closestColumn] = min(abs(zInput - lookUpTable))
% Extract the SA for that column:
SA = numbers(1, closestColumn)
  3 comentarios
Image Analyst
Image Analyst el 21 de Abr. de 2020
So why don't you call input() or inputdlg()?
zInput = input('Enter zInput : ');
Muhammad Imran
Muhammad Imran el 24 de Abr. de 2020
Hi. Actually i have to take two inputs from the user.
One is of soil profile type i.e Sa, Sb, Sc etc. Other one is that Z value i.e 0.075.
And then against these two inputs i have to pick a value of Cv from table which for example,
If user enters Z as 0.075 and Soil profile type as Sa then Cv value should be 0.06.
I will be thankful if you can comment on this.
Thanks

Iniciar sesión para comentar.

Categorías

Más información sobre String Parsing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by