Display strings and variable - cell array

조회 수: 16(최근 30일)
Telema Harry
Telema Harry 2021년 3월 15일
댓글: Telema Harry 2021년 3월 17일
I want to disply the output of my variable. so i created the following code.
food= { 'Rice','Quinoa','Tortilla','Lentils','Broccoli' }';
X % X is the output
for n =1:length(X)
The code is not working. Any help will be appreciated.


ANKUR KUMAR 2021년 3월 15일
편집: ANKUR KUMAR 2021년 3월 15일
Access the contents of cells by indexing with curly braces, {}.
food= { 'Rice','Quinoa','Tortilla','Lentils','Broccoli' }';
for n =1:length(food)
  댓글 수: 5
Telema Harry
Telema Harry 2021년 3월 17일
Thanks for the feedback. The code did work. However this is not the outcome I wanted.
I wanted to display, values of my X variable. X values are output from my optimization function.
Each index of my X(i) corresponds to same index in the food array.
Displaying only the values of X(i), one will not know the food associated with it. That is why i want to display the string i.e. food. associated with the value of X.

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




Community Treasure Hunt

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

Start Hunting!

Translated by