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.
54 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
0 Kommentare
Antworten (2)
KALYAN ACHARJYA
am 2 Mai 2020
Bearbeitet: KALYAN ACHARJYA
am 2 Mai 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 Kommentare
Walter Roberson
am 27 Nov. 2021
Array = [0 1 2 3 4 5];
syms alpha
solutions = arrayfun(@(U) solve(U*2 == U - 1*alpha*(U+2), alpha), Array)
Avenger2020
am 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)
0 Kommentare
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!