Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9078277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:34:47+00:00 2026-06-16T19:34:47+00:00

I want to save a string with its corresponding index in a matrix but

  • 0

I want to save a string with its corresponding index in a matrix but I am getting an error.

Here is a small example:

Mat_=[];            
Val1=[10,19,22,15,30];
Val2=20
Strs_=[];
for i= 1:length(Val1)
if abs(Val1(1,i))<abs(Val2)
            Str_={'Überschritten'};  
        else
            Str_={'Unterschritten'};
end
Strs_=[Strs_;Str_];
Mat_=[Mat_;i];
end
Mat_
Strs_
FMat=[Mat_,Strs_]
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T19:34:48+00:00Added an answer on June 16, 2026 at 7:34 pm

    You need a cell array to work with strings. To do this, you can preallocate a cell array and fill it.

    Val1 = [10,19,22,15,30];
    Val2 = 20;
    FMat = cell(length(Val1), 2); % Preallocate empty cell array
    for idx = 1:length(Val1)
        if abs(Val1(1,idx)) < abs(Val2)
            Str_ = 'Überschritten';  
        else
            Str_ = 'Unterschritten';
        end    
    FMat(idx, :) = {idx, Str_};
    end
    

    Your FMat cell array will be:

    1   'Überschritten'
    2   'Überschritten'
    3   'Unterschritten'
    4   'Überschritten'
    5   'Unterschritten'
    

    Notice that I also changed your loop variable i to idx. In MATLAB, i and j are defined as sqrt(-1). It is always a good idea to give your variables other names.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one string like 8/29/2011 11:16:12 AM . I want to save in
String urlString=http://myApp:8080/new/bin/save/SellerMyPage/WebHome i want to check whether above string contains the string MyPage between
I want to save a matrix to a text file, so I can read
I want to save and load my xml data using XmlReader. But I don't
I want to run multiple activities in BroadcastReacevier. But its not working, Only two
I want to save a file with name Привет Мир.jpg I receive a string
For a UIViewController , in case its view is unloaded, I want to save
I have a string which contains XML. I want to remove its first line
Hi i installed the neocomplcache script and its great but i want to use
I want save the username and password when user login, and I added the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.