Azzera filtri
Azzera filtri

How do I extract numbers from a matrix, use them in equations in the program and then assign all numbers in specific columns to variables.

46 visualizzazioni (ultimi 30 giorni)
I have a matrix that is about 18x26. I am attempting to extract specific numbers in the matrix and then assigning them to specific variables in order to solve an equation? Also, is it possible to extract a whole row from a matrix with the numbers automatically being assigned to specific variables? I think some of this will involve "if" statements and "for" loops based on the repetitive nature but I'm not sure.

Risposte (2)

KALYAN ACHARJYA
KALYAN ACHARJYA il 2 Mag 2020
Modificato: KALYAN ACHARJYA il 2 Mag 2020
mat_data(row,cloumns)
Use the conditional indexing, it great way to represents any matrix data. If you can share some specific example, it would be easy to explain.
Example
>> data=rand(18,26);
Lets exctract 2 row data, 2nd row with all columns
>> data(2,:)
ans =
Columns 1 through 12
0.9058 0.9595 0.3171 0.4984 0.2435 0.0540 0.7482 0.3998 0.0760 0.4039 0.2963 0.7948
Columns 13 through 24
0.1707 0.1174 0.2316 0.6538 0.5767 0.8175 0.3993 0.7379 0.5612 0.5830 0.3127 0.9686
Columns 25 through 26
0.9577 0.0012
More:
varivale_name=data(2,3)l ; Extract Single Element 2nd row & 3rd column
var_name=data(condition,:); Extract all rows, which satisfy the condition & all columns (":", represents all)
Also, is it possible to extract a whole row from a matrix with the numbers automatically being assigned to specific variables?
Yes, suggested to avoid the multiple variables names, consider array for scalars, or cell array for all others data types. Example: "whole single row data may be columns vector"
vec1=data(:,columns_num); columns_num or range of columns numbers like 1:5, 1 to 5
Any more clarifications, let me know with specific example
Good Wishes
  4 Commenti

Accedi per commentare.


Avenger2020
Avenger2020 il 5 Nov 2020
Instead of calling out a specific row. i want to call out a specific value from you matric. For example, calling out 0.2316 and giving it a variable zi. Then minus that value from the previous value in the same column (this will be zi-1)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by