Jesse Finnell asked . 2023-07-11

How do you access table data to be used with basic operators?

%% Test Sheet

%% Open data location

% find open Excel File (if multiple, chooses 'current')
DB = actxGetRunningServer('Excel.Application');

% choose correct tab
DBsheet = DB.ActiveWorkbook.Sheets;
DBsheet = DBsheet.get('Item',15);
DBsheet.Activate;

%% Import data

% Specify range and import data
range = 'L5:O14';
data = DBsheet.Range(range).Value;

% Setup transposition of data to fit table
[rows, columns] = size(data);
dataTranspose = cell(columns, rows);

% Loop to transpose one row at a time
for row = 1:rows;
    % Loop columns
    for col = 1:columns;
        % Transpose
        dataTranspose{col, row} = data{row, col};
    end
end

% Conver to table and assign variable names
data = array2table(dataTranspose, 'VariableNames',{'ATAD','TDS','Depth','Standard','SF','Design',...
    'Alt 1','Alt 2','Alt 3','Alt 4'});

%% find modifiers

% Determine TDS factor - This works fine
TDS = data{:,"TDS"};
for row = 1:numel(TDS);
    if TDS{row} > 1000
        ktds(row) = exp(9.65*10^(-5)*(2000-1000));
    else
        ktds = 1;
    end
end
% Find standard factor - this breaks as I need to access a Depth value that
% corresponds to the row of the loop
STD = data{:,"Standard"};
for row = 1:numel(STD);
    if STD{row} == 'DWA'
        standard(row) = 1-2.29*10^(-4)*(data(row,"Depth")/3.2808)^2+9.19*10^(-3)*(data(row,"Depth")/3.2808);
    else
        standard = 1;
    end
end

 
I have attached some code to help bring context to my question. I have a table of imported data from Excel that I need to run some formulas on using if loops. One loop works fine as it only uses a single value from my data table, but I cannot get the second loop to work.
 
The second loop formula requires a value from the corresponding row in another column of the data table to be used in the formula, but I can't get it to run.
 
When using paretheses or curly braces I receive the error:
>> for row = 1:numel(STD);
    if STD{row} == 'DWA'
        standard(row) = 1-2.29*10^(-4)*(data(row,"Depth")/3.2808)^2+9.19*10^(-3)*(data(row,"Depth")/3.2808);
    else
        standard = 1;
    end
end
Error using  / 
Arguments must be numeric, char, or
logical.

Is there a way to access these numerical values within the formula? I've tried dot indexing Value like in my previous code, but that receives an error as well. Do I need to use another nested loop? I'm still fairly inexperienced and have trouble diagnosing these problems.

 

indexing , loops , Data Types , Tables

Expert Answer

Kshitij Singh answered . 2024-05-17 20:19:19

I found a solution to my problem that looks to be the simplest. I used the cell2mat function in conjunction with the table indexing. See the following code,

 

for row = 1:numel(STD);
    if STD{row} == 'DWA'
        standard(row) = 1-2.29e-4*(cell2mat(data{row,'Depth'})/3.2808)^2+9.19e-3*(cell2mat(data{row,'Depth'})/3.2808);
    else
        standard = 1;
    end
end

 


Not satisfied with the answer ?? ASK NOW

Frequently Asked Questions

MATLAB offers tools for real-time AI applications, including Simulink for modeling and simulation. It can be used for developing algorithms and control systems for autonomous vehicles, robots, and other real-time AI systems.

MATLAB Online™ provides access to MATLAB® from your web browser. With MATLAB Online, your files are stored on MATLAB Drive™ and are available wherever you go. MATLAB Drive Connector synchronizes your files between your computers and MATLAB Online, providing offline access and eliminating the need to manually upload or download files. You can also run your files from the convenience of your smartphone or tablet by connecting to MathWorks® Cloud through the MATLAB Mobile™ app.

Yes, MATLAB provides tools and frameworks for deep learning, including the Deep Learning Toolbox. You can use MATLAB for tasks like building and training neural networks, image classification, and natural language processing.

MATLAB and Python are both popular choices for AI development. MATLAB is known for its ease of use in mathematical computations and its extensive toolbox for AI and machine learning. Python, on the other hand, has a vast ecosystem of libraries like TensorFlow and PyTorch. The choice depends on your preferences and project requirements.

You can find support, discussion forums, and a community of MATLAB users on the MATLAB website, Matlansolutions forums, and other AI-related online communities. Remember that MATLAB's capabilities in AI and machine learning continue to evolve, so staying updated with the latest features and resources is essential for effective AI development using MATLAB.

Without any hesitation the answer to this question is NO. The service we offer is 100% legal, legitimate and won't make you a cheater. Read and discover exactly what an essay writing service is and how when used correctly, is a valuable teaching aid and no more akin to cheating than a tutor's 'model essay' or the many published essay guides available from your local book shop. You should use the work as a reference and should not hand over the exact copy of it.

Matlabsolutions.com provides guaranteed satisfaction with a commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been empanelled after extensive research and quality check.

Matlabsolutions.com provides undivided attention to each Matlab assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work done at the best price in industry.